JPA Read Only Display

Toplink can use read-only mappings when several attributes on the feature map correspond to the same fields in the database, but only one of the mappings can write to the field.

Does JPA have a feature like writing annotations? I have one @ManyToOne and one @Column annotation that need to be mapped to the same field in the database.

     @ManyToOne (optional = false, fetch = FetchType.LAZY)
     @JoinColumn (name = "USR_ID", referencedColumnName = "USER_ID", nullable = false)
     private user user;

     / ** @generated ** /
     @Column (name = "USER_ID", nullable = false, length = 30)
     private String userId;

+7
java jpa
source share
1 answer

From here

Column annotations and an XML element define plug-in and updatable parameters. They allow you to exclude this column or foreign key field from the SQL INSERT or UPDATE statement. They can be used if restrictions in the table prevent insert or update operations. They can also be used if several attributes are mapped to the same database column, for example, to a foreign key field through matching ManyToOne and Id or Basic. By setting both inserted and updated to false, effectively mark the attribute as read-only.

So

@Column(name="USER_ID", nullable=false, length=30, updatable=false, insertable=false) private String userId; 

gotta do it

+14
source share

All Articles