-->
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.  [ 2 posts ] 
Author Message
 Post subject: Association with a property (more than a many-to-many rel.)
PostPosted: Fri Apr 10, 2009 6:47 am 
Newbie

Joined: Fri Apr 10, 2009 5:23 am
Posts: 2
Hibernate version: 3.3.1.GA

Mapping documents: -

Code between sessionFactory.openSession() and session.close(): -

Full stack trace of any exception that occurs: -

Name and version of the database you are using: Oracle 10gR2

The generated SQL (show_sql=true): -

Debug level Hibernate log excerpt: -

------------------------------------------------------------------------

Hello,

I have the following (I consider it simple) issue for which I didn't find an example for it:
- starting with two entitities: Profile and Position in a many-to-many relationship;
- the relationship is actually an association with an attribute.

Code:
Profile                           Position
  name      --- contains --->       name
  ...          with status          ...


and the db tables:

Code:
Profile             Profile_Position         Position
  IDProfile           IDProfile                IDPosition
  Name                IDPosition               Name
  ...                 Status                   ...


I created Profile and Position as clases, but I want to have another PersonPosition class that will contain the status property.
Person would contain a set of positions:
Code:
  private Set<PersonPosition> positions = new HashSet<PersonPosition>();

but I don't know how to design and map the PersonPosition entity since it doesn't have an id of its own: the table "Profile_Position" has a composite primary key consisting in IDProfile and IDPosition. And in the mapping, if I include this as a composite-id, then my "class name=PersonPosition" cannot include a Person and a Position as properties.

I really need a help on this or a simple example that would reflect this association, since it's not a simple many-to-many relation between Profile and Position entities.

Should this be related to the fact that "Hibernate doesn't manage persistent associations. If you want to manipulate an association, you must write exactly the same code you would write without Hibernate." ???

Please, I really need a help since I'm stuck right now.

Many thanks in advance.


Top
 Profile  
 
 Post subject: further details
PostPosted: Sat Apr 11, 2009 3:54 am 
Newbie

Joined: Fri Apr 10, 2009 5:23 am
Posts: 2
Hello everybody,

I am back with a couple of small details, hoping somebody will make this picture clear.

I have to take a bottom-up approach: I already have the database and tables:

Code:
Profile                 Profile_Position            Position
  IDProfile (pk)   <---   IDProfile  (pk,fk)     /->   IDPosition (pk)
  ProfileName             IDPosition (pk,fk)  -/       PositionName
                          Status


So, I have the two entities Profile and Position as simple POJO classes, but I don't know how to include the association between them.

Table Profile_Position was created not only to support the many-to-many relationship between them, but also to provide a Status for each such relationship. That's the reason I don't know how to map/design/include this association in the code.

The time is quite short and if I don't find a solution quickly to continue I have to give up Hibernate for now and do it all in the old JDBC style, which is pretty bad since I invested some time for learning Hibernate.

Please advice. Thank you.


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