简体   繁体   中英

OnetoOne Hibernate Mapping

In a One To One mapping, I wrote the following lines of code.

@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name="property", value= "post"))
@Id
@GeneratedValue(generator = "generator")
public int getContent_id() {
    return content_id;
}

What is the significance of @Parameter(name="property", value= "post") . If I don't write that line I'm getting an error

Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=in.codejava.personal.model.Content]

EDIT

When I changed the value = "post" to anything else like value="post123" etc it works. But it doesn't work when I completely remove that. Partial Code http://pastebin.com/CjEpqtXV

It allows telling the generator from which property the ID must be extracted (in this case: "post"). An entity could have several OnetoOne associations. You need to tell it which one of them contains the ID of your entity.

Note that this generator can be replaced by a standard JPA annotation on the OneToOne association containing the ID: @MapsId . The Hibernate documentation recommends its usage rather than the foreign generator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM