我很好奇這個錯誤休眠MappingException在java中
org.hibernate.MappingException: Unknown entity: xyz
我是新來的冬眠。歡迎任何建議。提前致謝。
我很好奇這個錯誤休眠MappingException在java中
org.hibernate.MappingException: Unknown entity: xyz
我是新來的冬眠。歡迎任何建議。提前致謝。
把@Entity
放在你的班級裏。
@Entity
@Table(name="tableName")
public class XYZ {
}
嗨,有必要把@Table(name =「tableName」), –
如果類名不匹配數據庫表姓名 –
你需要使用是否HBM文件,然後檢查你再配置file.and如果使用註釋,然後檢查是否已正確放置註釋類型包括檢查映射。需要更多細節來提供確切的解決方案
Dec 11, 2013 4:03:07 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Dec 11, 2013 4:03:07 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.8.Final}
Dec 11, 2013 4:03:07 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Dec 11, 2013 4:03:07 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Dec 11, 2013 4:03:07 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Dec 11, 2013 4:03:07 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Dec 11, 2013 4:03:07 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Dec 11, 2013 4:03:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Dec 11, 2013 4:03:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Dec 11, 2013 4:03:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Dec 11, 2013 4:03:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/testdb]
Dec 11, 2013 4:03:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
Dec 11, 2013 4:03:08 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Dec 11, 2013 4:03:08 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Dec 11, 2013 4:03:08 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Dec 11, 2013 4:03:08 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Dec 11, 2013 4:03:08 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
org.hibernate.MappingException: Unknown entity: com.sanjay.UserDetails
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1145)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1358)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:116)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:683)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:675)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:671)
at com.sanjay.UserTest.main(UserTest.java:21)
我想你可能會嘗試存儲/加載xyz
類的一個對象,它是無法與@Entity
註釋映射。任何你想使用Hibernate的類都應該使用註釋或使用XML描述符進行映射。
其他可能性是您的映射是正確的,但您既沒有明確列出hibernate.cfg.xml
文件中的xyz
也沒有啓用自動檢測實體。
如上所述,沒有看到一些實際的代碼,真的很難給出明確的答案。
xyz – gks
的名稱中沒有實體類顯示代碼好友。 –
顯示一些代碼真的有幫助。錯誤很簡單,正如@Gk指出的那樣,但是如果你需要幫助修復它,請嘗試發佈一些代碼 –