-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Non logical constraints for deleting entity
PostPosted: Tue Sep 22, 2009 8:25 am 
Newbie

Joined: Tue Sep 22, 2009 7:33 am
Posts: 2
Hello everybody, if anybody could tell me how to organize logical constraints at Hibernate side for relations between models. The problem is that we dont have phisicaly it at database side and should not create them.

We have 2 entities: Shop and City, Shop have not nullable City
If user removes City, which affiliate to some Shop, it not give any exception , but when we want preview this shop later - we take exception because hibernate cant find required city which was deleted.

I wonder, is any possibility to warn user that City which is trying to remove has relations with some Shop

Here are code for detail:
@SuppressWarnings("unchecked")
@Entity
@Table(name = "T_SHOP")
public class Shop extends BaseObject implements java.io.Serializable {
private Long shopId;
private City city;
private String address;
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CITY", nullable = false)
public City getCity() {
return city;
}

public void setCity(City city) {
this.city = city;
}
...
}



@Entity
@Table(name = "T_CITY")
public class City extends BaseObject implements java.io.Serializable {
private Long cityId;
private String cityName;
...
@SuppressWarnings("unchecked")
private List<Shop> shops = LazyList.decorate(new ArrayList<Shop>(), FactoryUtils.instantiateFactory(Shop.class));
...
@OneToMany(fetch=FetchType.LAZY,cascade = { CascadeType.PERSIST },mappedBy="city")
@Fetch(FetchMode.SELECT)
public List<Shop> getShops() {
return shops;
}

public void setShops(List<Shops> shops) {
this.shops = shops;
}
}

At DB constraints are absent phisically, and I should not create them (!) . It is possible to make some annotations at model that Hibernate checks this constraints at own logic ?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.