Use of Java constructors in persistent entities

Posted by Mr Morgan on Stack Overflow See other posts from Stack Overflow or by Mr Morgan
Published on 2010-05-27T22:32:22Z Indexed on 2010/05/27 22:51 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

Hello

I'm new to JPA and using persistence in Java anyway and I have two questions I can't quite work out: I have generated tags as:

@JoinColumn(name = "UserName", referencedColumnName = "UserName")
@ManyToOne(optional = false)
private User userName;
@JoinColumn(name = "DatasetNo", referencedColumnName = "DatasetNo")
@ManyToOne(optional = false)
private Dataset datasetNo;

But in one of the constructors for the class, no reference is made to columns UserName or DatasetNo whereas all other columns in the class are referenced in the constructor.

Can anyone tell me why this is? Both columns UserName and DatasetNo are 'foreign keys' on the entity Visualisation which corresponds to a database table of the same name. I can't quite work out the ORM.

And when using entity classes, or POJO, is it better to have class variables like:

private User userName;

Where an instance of a class is specified or simply the key of that class instance like:

private String userName;

Thanks

Mr Morgan.

© Stack Overflow or respective owner

Related posts about java

Related posts about class