Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: @NotNull with cascading
PostPosted: Thu Dec 05, 2013 2:47 pm 
Newbie

Joined: Fri May 04, 2007 5:48 am
Posts: 2
I continent-country-city entities (all different tables). I map both collections (Continent: List<Country> and Country: List<City>) as this:

Code:
@OneToMany(mappedBy="child", orphanRemoval=true, cascade=CascadeType.ALL)
   @Valid
   @NotNull
   @Size(min=1)


Lets say continent has 1 country and that country has 1 city in DB. I recreate exactly the same structure using 'new' keyword (with all ids set as if it was loaded from db). So I have 1 existing record on each level. Then I add to the collection of continent.countries new Country(new City) with some data set. When I try to call session.merge(continent) I'm getting a NotNull constraint error saying property cities can not be null. I think it complains about that newly created Country and its City. But If I remove that @NotNull constraint of the List<City> it works ok and populates a collection of List<City> cities with 1 record. So why does it complain at all?

In short:
session.merge(continent) updates existing countries and its cities. It also creates a newly added country and its newly added city. But it happens only when used without @NotNull on cities collection.


Top
 Profile  
 
 Post subject: Re: @NotNull with cascading
PostPosted: Thu Jan 02, 2014 5:31 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Hi,

I'm not sure what's causing this issue. It would help to see the source code of your entities, in particular how the collection-typed members are initialized.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.