0

I've got a client

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "cl_id")
private Long clId;

@JoinColumn(name = "vl_id", referencedColumnName = "vl_id")
@ManyToOne
private City cityId;

Whenever I create a new client this way:

Client c = new Client();
c.setCityId(new City());

and persist it. The city isn't persisted also if it doesn't exist. Wouldn't the city be persisted also unless the City object has got an Id ?

2
  • The last two statements seem to contradict each other. Can you explain a bit more? Commented Jan 19, 2013 at 13:27
  • It's just the variable that has a weired name. SetCityId() take a city as a parameter. It can take an already persisted city or a fresh one. Commented Jan 19, 2013 at 15:48

1 Answer 1

2

You have to enable cascading :

@JoinColumn(name = "vl_id", referencedColumnName = "vl_id")
@ManyToOne(cascade=CascadeType.PERSIST)
private City cityId;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.