Hello there,
just a conceptual question: is it possible to re-use a @Embeddable (In earlier versions of Hibernate: component) in different Entities using Hibernate 3.2 and EJB3 Annotations? I couldn't find anything in forum/ref/faq affirming or denying this...
Background: i'm currently porting a Hibernate 3.0 project to 3.2 and re-using a single @Embeddable in different classes won't work...
In the old version there was a component named BaseObject and everything persisted with hibernate had an instance of it. This object was or better: is still used to track who created/edited/deleted at what time a record.
Now we have to upgrade this to hibernate 3.2 and i annotated BaseObject with @Embeddable and used @Embedded in the classes using BaseObject. The program kept crashing with the exception as shown below until i made all @Embedded to @Transient except one class... So my guess is that re-using an @Embeddable in more than one @Entity is not possible...
Addendum
The fact that the row with id 0 cannot be found keeps confusing me, especially as i am trying to load a single entity.
This exception was produced using a simple testing class (simplified):
Code:
public static void main(String... args) {
AccountDAO adao = AccountFactory.getInstance().getAccoutDAO();
Account a = adao.findById(1l);
System.out.println(a); // Bang!
}
Many thanks and cheers,
Jakob
Hibernate:3.2 GA with Hibernate Annotations 3.2
Database:MySQL 4.1.15-1 (Debian Package)
Exception Stacktrace:Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [de.jakusys.fpvwsoft.model.Account#0]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:143)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:193)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:101)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:584)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1784)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2977)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:393)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:374)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:137)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:193)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:101)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at de.jakusys.fpvwsoft.dao.GenericHibernateDAO.findById(GenericHibernateDAO.java:74)
at de.jakusys.fpvwsoft.testclient.NewDAO.main(NewDAO.java:27)
Generated SQL:select account0_.account_id as account1_0_4_, account0_.base_deletedtimestamp as base2_0_4_, account0_.base_creationtimestamp as base3_0_4_, account0_.base_creator as base11_0_4_, account0_.base_deletor as base10_0_4_, account0_.base_editedtimestamp as base4_0_4_, account0_.base_expirationtimestamp as base5_0_4_, account0_.base_status as base6_0_4_, account0_.base_editor as base12_0_4_, account0_.account_login as account7_0_4_, account0_.fk_person_id as fk9_0_4_, account0_.account_password as account8_0_4_, account1_.account_id as account1_0_0_, account1_.base_deletedtimestamp as base2_0_0_, account1_.base_creationtimestamp as base3_0_0_, account1_.base_creator as base11_0_0_, account1_.base_deletor as base10_0_0_, account1_.base_editedtimestamp as base4_0_0_, account1_.base_expirationtimestamp as base5_0_0_, account1_.base_status as base6_0_0_, account1_.base_editor as base12_0_0_, account1_.account_login as account7_0_0_, account1_.fk_person_id as fk9_0_0_, account1_.account_password as account8_0_0_, account2_.account_id as account1_0_1_, account2_.base_deletedtimestamp as base2_0_1_, account2_.base_creationtimestamp as base3_0_1_, account2_.base_creator as base11_0_1_, account2_.base_deletor as base10_0_1_, account2_.base_editedtimestamp as base4_0_1_, account2_.base_expirationtimestamp as base5_0_1_, account2_.base_status as base6_0_1_, account2_.base_editor as base12_0_1_, account2_.account_login as account7_0_1_, account2_.fk_person_id as fk9_0_1_, account2_.account_password as account8_0_1_, account3_.account_id as account1_0_2_, account3_.base_deletedtimestamp as base2_0_2_, account3_.base_creationtimestamp as base3_0_2_, account3_.base_creator as base11_0_2_, account3_.base_deletor as base10_0_2_, account3_.base_editedtimestamp as base4_0_2_, account3_.base_expirationtimestamp as base5_0_2_, account3_.base_status as base6_0_2_, account3_.base_editor as base12_0_2_, account3_.account_login as account7_0_2_, account3_.fk_person_id as fk9_0_2_, account3_.account_password as account8_0_2_, person4_.person_id as person1_1_3_, person4_.base_deletedtimestamp as base2_1_3_, person4_.base_creationtimestamp as base3_1_3_, person4_.base_creator as base25_1_3_, person4_.base_deletor as base23_1_3_, person4_.base_editedtimestamp as base4_1_3_, person4_.base_expirationtimestamp as base5_1_3_, person4_.base_status as base6_1_3_, person4_.base_editor as base24_1_3_, person4_.person_alleinheim as person7_1_3_, person4_.person_birthday as person8_1_3_, person4_.erreichbarkeit_phone_home as erreichb9_1_3_, person4_.erreichbarkeit_phone_arbeit as erreich10_1_3_, person4_.erreichbarkeit_email as erreich11_1_3_, person4_.erreichbarkeit_fax as erreich12_1_3_, person4_.erreichbarkeit_phone_mobile as erreich13_1_3_, person4_.erreichbarkeit_www as erreich14_1_3_, person4_.person_firstname as person15_1_3_, person4_.person_lastname as person16_1_3_, person4_.person_notfallerreichbarkeit as person17_1_3_, person4_.person_remarks as person18_1_3_, person4_.person_sex as person19_1_3_, person4_.address_street as address20_1_3_, person4_.address_city as address21_1_3_, person4_.address_zip as address22_1_3_ from sys_account account0_ inner join sys_account account1_ on account0_.base_creator=account1_.account_id left outer join sys_account account2_ on account1_.base_deletor=account2_.account_id left outer join sys_account account3_ on account1_.base_editor=account3_.account_id left outer join person person4_ on account1_.fk_person_id=person4_.person_id where account0_.account_id=?
Code: