Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Simple unidirectional @OneToOne

$
0
0
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.
Code:

session.persist(author);
Code:

@Repository
public interface AuthorRepository
        extends JpaSpecificationExecutor<Author>,
        JpaRepository<Author, Integer> {}

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().

Viewing all articles
Browse latest Browse all 297

Trending Articles