java - Hibernate annotations and foreign key relationship -


I have an annotated domain object for hibernate support like this.

@Entity @Table (name = "INPUT") Public Classroom AppInput {/ ** * Unique ID * / @ Id @ GeneratedValue @ column for this request (name = "INPUT_ID") Private long request id; / ** * * / @ column (name = "EMAIL_ID") Private string email id; / ** * * / @ column (name = "REQUEST_DATE") Private date request date; / ** * * / @ column (name = "INPUT_STATUS") Private variable status; / ** * * / @ column (name = "EXPECTED_ORDER_DATE") private date expected ORDDt; // Getter and Setters}

Property email ID is a foreign key that is to call the email ID in the user table. Let's say I like AppInput.java Personal User userDetails; I add an asset to , how do I annotate it, so whenever I take the input from DB, the related user details will also populate?

property emailId is a foreign key that refers to calling the email id in the user table Used to be.

Then do not add email id property, add a user .

(...) How do I comment on this so that whenever I get input from db, the details of this user are also populated?

Definitely it can be a too many a or OneToOne but I think it's a ManyToOne :

  @ManyToOne (fetch = FetchType.EAGER) @JoinColumn (name = "USERDETAILS_EMAIL_ID", referenced column name = "EMAIL_ID") private user user;  

Fetch annotation element is for display purpose, EAGER is actually the default value when the name and In the referenced column the annotation element JoinColumn is also optional. Under a brief summary from the JPA specification:

11.1.21 Join column annotation

JoinColumn to use annotations to join any one An entity association or element collection is used to specify a column.

Annotation elements are listed in Table 20 which can be specified for JoinColumn annotations and their default values.

If the insert column annotation is omitted, a single column is assumed and the default values ​​described in Table 20 are applied.

Name defines the name of the annotation element Foreign key column left Annotation element (except referenced column name ) refers to this column and the same For coding such as column annotation.

If the referenced columnname element is unavailable, the foreign key is referenced to the primary key of the table referenced.

See Table 20 in the description for complete and complete details.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -