R
R
Roston2011-12-12 22:31:19
PostgreSQL
Roston, 2011-12-12 22:31:19

Hibernate 3 OneToOne relationship. (PostgreSQL)

Good evening. I can not solve the problem: how to save an object in which there is another object in the database? Relationship of one to another One to one. I have a Client and an Account. A client can only have one account. The actual implementation of

**Account.class** Client.class I manually initialize the Client and the Account, then set the account to the Client and try to save it. Here's what I get As you can see from here, the database is being saved to client_id = 0; How can this problem be solved? Thank you!

@Column(name = "client_id")
@GeneratedValue(generator = "gen")
@GenericGenerator(name = "gen", strategy = "foreign", parameters = { @Parameter(name = "property", value = "clientDTO") })
private int client_id;




@OneToOne(cascade = CascadeType.ALL)
private AccountDTO accountDTO;



> java.sql.BatchUpdateException: Batch entry 0 insert into
> public.accounts (balance, client_id, comment, credit_limit, id) values
> (1000.0, 0, comment, 0.0, 8) was aborted. Call getNextException to
> see the cause.


Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vtysh, 2011-12-14
@vtysh

Use OneToMany both ways

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question