-->
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.  [ 6 posts ] 
Author Message
 Post subject: entity-name save problem
PostPosted: Sat May 19, 2007 1:11 pm 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
Hi all,

I have one bean (Menu) mapped twice in my hbm.xml using different entity-name:

Code:
<class name="Menu" table="nav_stage_menu" entity-name="stageMenu">
...

Code:
<class name="Menu" table="nav_public_menu" entity-name="publicMenu">
...

I can easily RETRIVE information from both tables using such a syntax:
Code:
Menu m = (Menu) hsc.session.createQuery("from "+boundary+"Menu m where m.uid=?")
         .setParameter(0, uid)
         .uniqueResult();

where boundary is a string "stage" or "public"

Here is my question...

Which is the right syntax to save an instance of Menu m, since the Exeception I get from Hibernate, when I execute
Code:
hsc.session.save(m);

is, obviously, this:
Code:
Unknown entity: backend.entities.navigation.Menu






ps:
I'm trying this awful thing but it reeeeeeallly sucks, since it's not Hibernate (and even it does not work):
Code:
hsc.session.createQuery("insert into "+boundary.getValue()+"Menu (parent, label) values (?, ?)")
         .setParameter(0, m.getParent())
         .setParameter(1, m.getLabel());


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 19, 2007 1:38 pm 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
Why are you having the same variable name for both entities


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 19, 2007 1:45 pm 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
Because I have only ONE entity that is bound to both the tables, to the "stage" table and to the "public" one.

I do not need two entities since the Menu's properties are the same in both cases


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 19, 2007 1:50 pm 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
I don't know the exact answer for you. But my thought is create a base class entity and derive two classes out of it. Do not put attributes in the derived class, in your hbm map the derived classes. This will help you in scalability point of view too. Suppose if the Menu changes tomorrow u can just add those attributes in the corresponding derived class. You should be good to go. Let me know if this helps


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 19, 2007 2:00 pm 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
My solution has been taken directly from the reference at the chapter "Mapping a class more than once"... but the authors do not explain the full story there...


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 5:44 am 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
----- SOLUTION FOUND -----

Simply do this:

Code:
hsc.session.save(boundary.getValue()+"Menu", m);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.