openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Reeder <reeder...@gmail.com>
Subject Re: Learning relationships - dazed and confused
Date Tue, 18 Nov 2008 06:19:16 GMT
You have too many annotations and the wrong ones.  :-(

It should be something like

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER,  
mappedBy = "userId")
private Collection<UserProperties> userProperties;

and

@ManyToOne()
@JoinColumn(name="UserInfo")
private Integer userId;


See especially
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/manual.html#jpa_overview_meta_mappedby

I may have mistyped something, but you want something about like that.



On Nov 17, 2008, at 11:15 PM, <cobbra@windstream.net> wrote:

> Hello all,
>
> I am trying to teach myself OpenJPA.  I've done a bit of database  
> relationships but I'm confused while trying to set up entity  
> relationships for a particular situation.  I'm hoping someone will  
> be kind enough to point me in the right direction.
>
> Here's my scenario:
> I have two tables: UserInfo and UserProperties
> Each UserInfo will have a collection of UserProperties
>
> I'm trying to define UserInfo as:
> @Entity
> @Table(name="UserInfo")
> public class UserInfo implements Serializable {
> ....
> @Id
> private Long id;
>
> @OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
> @JoinColumn(name="prop_id", referencedColumnName="userId")
> private Collection<UserProperties> userProperties;
>
> <etc>
>
> And I have UserProperties defined like:
> @Entity
> @Table(name="userproperties")
> public class UserProperties implements Serializable {
>
> @Id
> private Integer id;
> 	
> @OneToOne(fetch=FetchType.LAZY)
> @JoinColumn(name="user_id", referencedColumnName="id")
> private Integer userId;
>
> But I get errors while trying to deploy:
> <openjpa-1.0.2-r420667:627158 fatal user error>  
> org.apache.openjpa.util.MetaDataException: The type of field  
> "com.whitetail.sawhorse.data.UserProperties.userId" isn't supported  
> by declared persistence strategy "OneToOne".  Please choose a  
> different strategy.
>
> I'm not sure how to set up the join type in UserProperties.   
> Basically, I will have many UserInfo entities, each with a  
> collection of UserProperties.  The UserProperties will be joined to  
> a single UserInfo; primarily because each UserInfo can have an  
> arbitrary set of UserProperties.
>
> Is this possible?  If so, can anyone offer any suggestions on how to  
> set it up?
>
> I'm basically lost at this point.
>
> Thanks in advance!
> Randy


Mime
View raw message