Hi,
I found this simple example, but I'm surprised there is no easy solution as I would think this was a common user case. (Using Spring 3.2, Hibernate 4.2.1 and Mysql).
http://fruzenshtein.com/one-to-one-u...l-primary-key/
I wanted to avoid calling persist, so I tried various solutions (@PrimaryKeyJoinColumn, bidirectional, etc.) but I could not find a way to get this to work.
I assume the problem is that that Author needs to be persisted first to get the auto-generated Id, but I thought that Hibernate would handle this.
I was trying to find an elegant way to use this via a repository. If calling "persist" is the only solution, where/how do I add this in a repository.
Any hints appreciated...
Just to clarify:
I want to be able to call repository.save(author) and have everything persisted. I want to avoid have to persist the author, get the id, set the id, and then save().
I found this simple example, but I'm surprised there is no easy solution as I would think this was a common user case. (Using Spring 3.2, Hibernate 4.2.1 and Mysql).
http://fruzenshtein.com/one-to-one-u...l-primary-key/
I wanted to avoid calling persist, so I tried various solutions (@PrimaryKeyJoinColumn, bidirectional, etc.) but I could not find a way to get this to work.
I assume the problem is that that Author needs to be persisted first to get the auto-generated Id, but I thought that Hibernate would handle this.
I was trying to find an elegant way to use this via a repository. If calling "persist" is the only solution, where/how do I add this in a repository.
Code:
session.persist(author);
Code:
@Repository
public interface AuthorRepository
extends JpaSpecificationExecutor<Author>,
JpaRepository<Author, Integer> {}
Just to clarify:
I want to be able to call repository.save(author) and have everything persisted. I want to avoid have to persist the author, get the id, set the id, and then save().