English 中文(简体)
Grails GORM
原标题:Grails GORM many-to-many relationship and deleting of jointable-entries

我有2个班级的汽车和停车场。 他们有一米:n关系,因此一辆汽车有许多停车场,一辆汽车多。

I have a garage_has_car table in my database, where the relations are stored. I have configured set belongsTo on the car to Garage

static belongsTo = [  Garage ]

如果我清扫停车场和储蓄的汽车收集工作,则将车库中的相应条目删除。

但是,如果我清除了车上的垃圾收集并节省费用,那么车库中相应的条目——has车桌上没有删除!

我如何能够实现这一行为?

www.un.org/spanish/ecosoc 1 (关于关系的定义):

婚姻关系是:

cars column: deskriptor_id ,joinTable: garage_has_cars 

Car

static belongsTo = [  Garage ]
garages column: car_id ,joinTable: garage_has_cars 

我也曾在国际排雷中心问这个问题,有人回答:

(...) grails many to many relationships are always only cascade one direction. also many-to-many relationships in grails are horribly inefficient with how they get mapped in hibernate. don t use them. create a joinclass domain object CarGarage with 1 car and 1 garage. make cars and garages properties of your classes transients and add get and add methods to the car and garage classes which use your joinclass for maintaining the relationship. you also want to disable versioning in the join class here s some info can be found in this presentation http://burtbeckwith.com/blog/files/169/gorm%20grails%20meetup%20presentation.pdf and the notes of it are here: Grails: Many-to-Many without hasMany/belongsTo - instead using native 3NF - Searching full text

我之所以这样说,是因为它可以帮助问题与我一样的人。 一旦我有时间实施这些变化,我也将更新这个问题。

最佳回答

Just answering to remove from the unanswered list.

(...) grails many to many relationships are always only cascade one direction. also many-to-many relationships in grails are horribly inefficient with how they get mapped in hibernate. don t use them. create a joinclass domain object CarGarage with 1 car and 1 garage. make cars and garages properties of your classes transients and add get and add methods to the car and garage classes which use your joinclass for maintaining the relationship. you also want to disable versioning in the join class here s some info can be found in this presentation http://burtbeckwith.com/blog/files/169/gorm%20grails%20meetup%20presentation.pdf and the notes of it are here: Grails: Many-to-Many without hasMany/belongsTo - instead using native 3NF - Searching full text

问题回答

暂无回答




相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签