Hibernate generates double constraints for FK?
-----------------------------------------------
Key: HHH-6898
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6898
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.8
Environment: Progress, java 7, win 7, intellij 11.
Reporter: Henrik Korsbæk
Priority: Minor
When using naming of relations (@org.hibernate.annotations.ForeignKey(name =
"undermyndighed_FK")) Hibernates generates both a constraint using the name AND
an identical constraint using a generated name:
alter table Myndighedsrelationer add constraint FK382528159E2E9E11 foreign key
(undermyndighedId) references Myndighed;
alter table Myndighedsrelationer add constraint undermyndighed_FK foreign key
(undermyndighedId) references Myndighed;
and
alter table Myndighedsrelationer add constraint FK38252815C1F7CE95 foreign key
(overmyndighedId) references Myndighed;
alter table Myndighedsrelationer add constraint overmyndighed_FK foreign key
(overmyndighedId) references Myndighed;
It should only generate:
alter table Myndighedsrelationer add constraint undermyndighed_FK foreign key
(undermyndighedId) references Myndighed;
alter table Myndighedsrelationer add constraint overmyndighed_FK foreign key
(overmyndighedId) references Myndighed;
Classes:
_________________________________________________________________________________________________________________________
package dk.ttt.rrr.model.rrr.myndighed;
@dk.team.foundation.bean.mdsd.BaseClazz(extensionClazz =
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer.class)
@javax.persistence.MappedSuperclass
abstract public class AbstractMyndighedsrelationer extends
dk.team.mddexample.model.AbstractEntity {
private static final long serialVersionUID = 1404123320L;
public static dk.team.foundation.bean.mdsd.runtime.RuntimeMetaClazz metaType =
(dk.team.foundation.bean.mdsd.runtime.RuntimeMetaClazz)
dk.team.mddexample.meta.RuntimeMetaModelFactory.getMetaModel()
.findById("ID_4F134AAD_7D6B_4a0d_B367_247AC5286AFA");
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST,
javax.persistence.CascadeType.REFRESH}
, fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.JoinColumn(nullable = false, name = "undermyndighedId")
@org.hibernate.annotations.ForeignKey(name = "undermyndighed_FK")
private dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed undermyndighed;
@javax.persistence.Enumerated(javax.persistence.EnumType.STRING)
@javax.persistence.Column(name = "type_", nullable = false)
private dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationstype type;
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST,
javax.persistence.CascadeType.REFRESH}
, fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.JoinColumn(nullable = false, name = "overmyndighedId")
@org.hibernate.annotations.ForeignKey(name = "overmyndighed_FK")
private dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed overmyndighed;
public dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed getUndermyndighed() {
if (undermyndighed instanceof org.hibernate.proxy.HibernateProxy) {
undermyndighed = (dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed)
((org.hibernate.impl.SessionImpl) ((org.hibernate.proxy.HibernateProxy) undermyndighed)
.getHibernateLazyInitializer()
.getSession()).getPersistenceContext()
.unproxyAndReassociate(undermyndighed);
}
return undermyndighed;
}
@java.lang.SuppressWarnings({"serial",
"unchecked",
"rawtypes"
})
public void setUndermyndighed(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed parameter) {
new
dk.team.foundation.bean.bidirectional.ManyToOneWrapper<dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed,
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer>((dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer)
this) {
@Override
protected void addManySideObjectToOneSideCollection(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed oneSide,
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide) {
((dk.team.foundation.bean.WrappedSet<dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer>)
oneSide
.getOvermyndighedCollection()).getWrappedCollection()
.add(manySide);
}
@Override
protected void removeManySideObjectFromOneSideCollection(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed oneSide,
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide) {
((dk.team.foundation.bean.WrappedSet<dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer>)
oneSide
.getOvermyndighedCollection()).getWrappedCollection()
.remove(manySide);
}
@Override
protected dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed
getOneSideObjectInManySideObject(
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide) {
return ((dk.ttt.rrr.model.rrr.myndighed.AbstractMyndighedsrelationer)
manySide).undermyndighed;
}
@Override
protected void setOneSideObjectInManySideObject(
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide,
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed oneSide) {
((dk.ttt.rrr.model.rrr.myndighed.AbstractMyndighedsrelationer)
manySide).undermyndighed = oneSide;
}
}.updateOneSideObject(parameter);
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationstype getType() {
return type;
}
public void setType(
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationstype parameter) {
this.type = parameter;
}
public dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed getOvermyndighed() {
if (overmyndighed instanceof org.hibernate.proxy.HibernateProxy) {
overmyndighed = (dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed)
((org.hibernate.impl.SessionImpl) ((org.hibernate.proxy.HibernateProxy) overmyndighed)
.getHibernateLazyInitializer()
.getSession()).getPersistenceContext()
.unproxyAndReassociate(overmyndighed);
}
return overmyndighed;
}
@java.lang.SuppressWarnings({"serial",
"unchecked",
"rawtypes"
})
public void setOvermyndighed(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed parameter) {
new
dk.team.foundation.bean.bidirectional.ManyToOneWrapper<dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed,
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer>((dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer)
this) {
@Override
protected void addManySideObjectToOneSideCollection(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed oneSide,
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide) {
((dk.team.foundation.bean.WrappedSet<dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer>)
oneSide
.getUndermyndighedCollection()).getWrappedCollection()
.add(manySide);
}
@Override
protected void removeManySideObjectFromOneSideCollection(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed oneSide,
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide) {
((dk.team.foundation.bean.WrappedSet<dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer>)
oneSide
.getUndermyndighedCollection()).getWrappedCollection()
.remove(manySide);
}
@Override
protected dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed
getOneSideObjectInManySideObject(
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide) {
return ((dk.ttt.rrr.model.rrr.myndighed.AbstractMyndighedsrelationer)
manySide).overmyndighed;
}
@Override
protected void setOneSideObjectInManySideObject(
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer manySide,
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed oneSide) {
((dk.ttt.rrr.model.rrr.myndighed.AbstractMyndighedsrelationer)
manySide).overmyndighed = oneSide;
}
}.updateOneSideObject(parameter);
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer withUndermyndighed(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed undermyndighed) {
setUndermyndighed(undermyndighed);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer withType(
dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationstype type) {
setType(type);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer withOvermyndighed(
dk.ttt.rrr.model.rrr.myndighed.IndlandskMyndighed overmyndighed) {
setOvermyndighed(overmyndighed);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighedsrelationer) this;
}
public dk.team.foundation.bean.mdsd.runtime.RuntimeMetaClazz getMetaType() {
return metaType;
}
}
__________________________________________________________________________________________________________________________
package dk.ttt.rrr.model.rrr.myndighed;
@dk.team.foundation.bean.mdsd.BaseClazz(extensionClazz =
dk.ttt.rrr.model.rrr.myndighed.Myndighed.class)
@javax.persistence.Entity
@javax.persistence.Inheritance(strategy = javax.persistence.InheritanceType.SINGLE_TABLE)
@javax.persistence.DiscriminatorColumn(name = "DTYPE", discriminatorType =
javax.persistence.DiscriminatorType.STRING, length = 255)
@org.hibernate.annotations.DiscriminatorOptions(force = true)
@javax.persistence.Table(name = "Myndighed")
abstract public class AbstractMyndighed extends dk.team.mddexample.model.AbstractEntity {
private static final long serialVersionUID = 2811393302L;
public static dk.team.foundation.bean.mdsd.runtime.RuntimeMetaClazz metaType =
(dk.team.foundation.bean.mdsd.runtime.RuntimeMetaClazz)
dk.team.mddexample.meta.RuntimeMetaModelFactory.getMetaModel()
.findById("ID_421765D5_5F61_4a14_8C2E_F8F8787A9B78");
@javax.persistence.Basic
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
@javax.persistence.Column(name = "ikraefttraedelsesdato", nullable = false)
private java.util.Date ikraefttraedelsesdato;
@javax.persistence.Basic
@javax.persistence.Column(name = "kode", nullable = false)
private int kode;
@javax.persistence.Basic
@javax.persistence.Column(name = "navn", nullable = false)
private String navn;
@javax.persistence.Basic(optional = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
@javax.persistence.Column(name = "ophoersdato")
private java.util.Date ophoersdato;
@javax.persistence.Basic
@javax.persistence.Column(name = "sekundaer", nullable = false)
private boolean sekundaer;
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST,
javax.persistence.CascadeType.REFRESH}
, targetEntity = dk.ttt.rrr.model.rrr.sag.SagsRolle.class, mappedBy =
"myndighed", fetch = javax.persistence.FetchType.LAZY)
private java.util.Set<dk.ttt.rrr.model.rrr.sag.SagsRolle> rolleCollection = new
java.util.HashSet<dk.ttt.rrr.model.rrr.sag.SagsRolle>();
public java.util.Date getIkraefttraedelsesdato() {
return ikraefttraedelsesdato;
}
public void setIkraefttraedelsesdato(java.util.Date parameter) {
this.ikraefttraedelsesdato = parameter;
}
public int getKode() {
return kode;
}
public void setKode(int parameter) {
this.kode = parameter;
}
public String getNavn() {
return navn;
}
public void setNavn(String parameter) {
this.navn = parameter;
}
public java.util.Date getOphoersdato() {
return ophoersdato;
}
public void setOphoersdato(java.util.Date parameter) {
this.ophoersdato = parameter;
}
public boolean isSekundaer() {
return sekundaer;
}
public void setSekundaer(boolean parameter) {
this.sekundaer = parameter;
}
@java.lang.SuppressWarnings({"serial",
"unchecked",
"rawtypes"
})
public java.util.Set<dk.ttt.rrr.model.rrr.sag.SagsRolle> getRolleCollection() {
return new
dk.team.foundation.bean.bidirectional.OneToManySetWrapper<dk.ttt.rrr.model.rrr.myndighed.Myndighed,
dk.ttt.rrr.model.rrr.sag.SagsRolle>((dk.ttt.rrr.model.rrr.myndighed.Myndighed) this,
rolleCollection) {
@Override
protected dk.ttt.rrr.model.rrr.myndighed.Myndighed
getOneSideObjectInManySideObject(
dk.ttt.rrr.model.rrr.sag.SagsRolle manySideObject) {
return manySideObject.getMyndighed();
}
@Override
protected void setOneSideObjectInManySideObject(
dk.ttt.rrr.model.rrr.sag.SagsRolle manySideObject,
dk.ttt.rrr.model.rrr.myndighed.Myndighed oneSideObject) {
manySideObject.setMyndighed(oneSideObject);
}
};
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighed withIkraefttraedelsesdato(
java.util.Date ikraefttraedelsesdato) {
setIkraefttraedelsesdato(ikraefttraedelsesdato);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighed) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighed withKode(int kode) {
setKode(kode);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighed) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighed withNavn(String navn) {
setNavn(navn);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighed) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighed withOphoersdato(
java.util.Date ophoersdato) {
setOphoersdato(ophoersdato);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighed) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighed withSekundaer(
boolean sekundaer) {
setSekundaer(sekundaer);
return (dk.ttt.rrr.model.rrr.myndighed.Myndighed) this;
}
public dk.ttt.rrr.model.rrr.myndighed.Myndighed addToRolleCollection(
dk.ttt.rrr.model.rrr.sag.SagsRolle... values) {
getRolleCollection().addAll(java.util.Arrays.asList(values));
return (dk.ttt.rrr.model.rrr.myndighed.Myndighed) this;
}
public dk.team.foundation.bean.mdsd.runtime.RuntimeMetaClazz getMetaType() {
return metaType;
}
}
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira