JPA/Hibernate Persist cascades even if it shouldn't?

Bernate and JPA automatically make persistent all the modifications made to persistent entities while they are attached to the session. That's the whole point of an ORM: you load a persistent object, modify it, and the new state is automatically persisted at the commit of the transaction, without any need to call persist, merge, save or any other method.

Bernate and JPA automatically make persistent all the modifications made to persistent entities while they are attached to the session. That's the whole point of an ORM: you load a persistent object, modify it, and the new state is automatically persisted at the commit of the transaction, without any need to call persist, merge, save or any other method. Note that calling persist on a persistent entities (except for its cascading side-effects) makes no sense.

Persist is to make a transient entity (i.e. A new one, not in the database yet, with no generated ID) persistent.

Nevermind. I set up my tests in a hurry and made some mistakes. The tests were supposed to run with detached objects.

I ran into a new issue now, so please check the edited question. Thanks. – ccc Nov 3 at 12:44 You have a really strange schema here: it would be impossible to change the language of a book without changing its primary key.

I would use single-column surrogate keys. And if you can't, then I would have two seperate libcod columns: one for the book's primary key, and one for the language foreign key. – JB Nizet Nov 3 at 13:10 The problem is I can't change the database structure.

I HAVE to work with this legacy DB so I am trying to find the most elegant way of describing and managing it via JPA. Of course I'd prefer to have simple id's for PK's and FK's, but ... – ccc Nov 3 at 16:13.

You can only have one mutator for the libcod. Probably, what you should do is leave the libcod getter in the BookPK class, and in the Language class, use a joincolumn reference with a ref back to the libcod. It works fine for single embedded PK classes, but for multiple PK classes, you may have to play around.So, in your Language class, you would have this.

@javax.persistence. Entity public class Language { private LanguagePK id; private Integer libcod; @javax.persistence. EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "lngcod", column = @Column(name = "LNGCOD", nullable = false)), @AttributeOverride(name = "libcod", column = @Column(name = "LIBCOD", nullable = false)) }) public LanguagePK getId() { return this.

Id; } public void setId(LanguagePK id) { this. Id = id; } @ManyToOne(fetch = FetchType. LAZY) @JoinColumn(name = "LIBCOD", insertable = false , updatable = false) public Integer getLibcod() { return this.

Libcod; }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions