-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Re-using @Embeddable in different Entities?
PostPosted: Sun Oct 29, 2006 6:25 pm 
Newbie

Joined: Wed Mar 15, 2006 2:25 pm
Posts: 4
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:


Top
 Profile  
 
 Post subject: Re: Re-using @Embeddable in different Entities?
PostPosted: Mon Nov 06, 2006 6:35 am 
Newbie

Joined: Tue May 10, 2005 10:54 am
Posts: 16
Location: Italy
Hi, I've the same problem.

Code:
Ocriga riga= riga_DAO.findById(id, false);

then I've tried to do some control on my object riga, but even if I haven't a match with my id riga isn't null... and if I've tried to bring value like
riga.getMyField() for some control I've the exception.
Do you have solve it?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 3:02 pm 
Newbie

Joined: Wed Mar 15, 2006 2:25 pm
Posts: 4
Hi there,
after some long nights i (think i) finally found the problem or at least a way to circumvent this problem.

After studying the generated SQL i came to the conclusion that hibernate had a problem with the circular reference that results from the database layout given by this project.
Code:
Java Classes          BaseObject as
persisted as            @Embeddable
@Entity

      +-------------------+
     \|/                  |
-----------          --------------
| Account |-------+->| BaseObject |
-----------       |   -------------
                  |
----------------  |
| OtherClasses |--+
----------------

So what i think went wrong is that hibernate tries to fetch all assosiations including BaseObject and all dependencies from BaseObject. If i want to retrieve OtherClasses e.g. this is ok. But as soon as i fetch Account this wouldnt work any more.

The Solution to this was to change the fetch-behaviour from eager to lazy. After changing this the generated SQL was correct (and it's faster now)...

Hope this helps. :-)

_________________
Cheers,
Jakob


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.