Hi,
I am trying to map 2 different parent classes with a one-to-many to a set of child classes of the same type, but then hibernate complains that _propertyNameBackref is already mapped.
This is the current situation:
Code:
// The parent classes
@Entity
@Table(name="t_holiday")
public class Holiday implements Serializable {
private static final long serialVersionUID = -3948723008730842068L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@OneToMany(cascade=CascadeType.ALL)
@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@JoinColumn(name="item_id", nullable=false)
private Set<Translation> names;
...
}
@Entity
@Table(name="t_request_type")
public class RequestType implements Serializable {
private static final long serialVersionUID = -5099401234648927543L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@OneToMany(cascade=CascadeType.ALL)
@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@JoinColumn(name="item_id", nullable=false)
private Set<Translation> names;
@OneToMany(cascade=CascadeType.ALL)
@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@JoinColumn(name="item_id", nullable=false)
private Set<Translation> descriptions;
// getters and setters omitted
}
// the child class
@Entity
@Table(name="t_translations")
public class Translation implements Serializable {
private static final long serialVersionUID = -6518609736903575223L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@Column(name="locale", nullable=false)
private String locale;
private String description;
@Enumerated(EnumType.STRING)
private TranslationCategory category;
// getters and setters ommitted
}
The exception I get is this:
Code:
org.hibernate.MappingException: Duplicate property mapping of _namesBackref found in be.xplore.verlof.model.Translation
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:477)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:816)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:734)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1333)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1299)
... 120 more
I tried this with both HIbernate 3.2.6 and 3.3.0 (GA) but they both give the same error, and I know there was a resolved JIRA issue for this:
http://opensource.atlassian.com/project ... e/HHH-2598
However, since I still have this issue in the latest version I assume I am doing this the wrong way.
I really wouldn't know how I could map this kind of relationship differently, any help is welcome here.
Thanks in advance.