-->
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.  [ 5 posts ] 
Author Message
 Post subject: New to Hibernate and JPA - few questions
PostPosted: Tue Apr 07, 2009 9:05 pm 
Newbie

Joined: Tue Apr 07, 2009 9:00 pm
Posts: 9
I'm new to Hibernate and JPA and have a few questions, in order of priority.

1) I have two properties/columns (not sure on the right terminology) that I want to make unique together. How do I do this without nested annotations?

2) What exactly is does MapKey do? How does it work?

3) If I define a ManyToOne relationship, why should I define a OneToMany on the other end?

Thanks,
Bradford


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 4:24 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
1) What do you mean with nested annotations? It is possible:
Code:
@Table(name="tbl_sky",
    uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
)

Do you mean @UniqueConstraint as nested annotation? If yes, why do you want to do it without it?

2)You can use MapKey to define the key of a Map, where the MapKey relates to the property (of the map's value-entity) to be used as key.

3) It's not mandatory to make an association bidirectional, though it's recommended. So you can keep your ManyToOne without your OneToMany on the other side.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 4:34 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
mmerder wrote:
3) It's not mandatory to make an association bidirectional, though it's recommended.


No, it's not!

http://in.relation.to/Bloggers/PersistentCollectionsAreAFeature

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 9:34 am 
Newbie

Joined: Tue Apr 07, 2009 9:00 pm
Posts: 9
Thanks for the quick replies.

I'm trying to use JPA and Hibernate in Scala. Currently, it does not support nested annotations, so the following will not work:

@Table(name="tbl_sky",
uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
)

I was wondering if I could define this in some XML file. If so, which XML file?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 12:16 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You can override annotations using xml.

Probably the easiest way would be placing a file orm.xml in your META-INF folder, where persistence.xml is placed. This file gets read automatically.

If you need more information on how to map via xml, see the reference guide.

_________________
-----------------
Need advanced help? http://www.viada.eu


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