HHH-5472 : Test case for delaying saving an entity with non-nullable transient entities

This commit is contained in:
Gail Badner 2011-11-22 23:31:57 -08:00
parent ba764816b9
commit 52969e9561
20 changed files with 1434 additions and 0 deletions

View File

@ -0,0 +1,83 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class A extends AbstractEntity {
private static final long serialVersionUID = 864804063L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "a")
private java.util.Set<B> bCollection = new java.util.HashSet<B>();
/**
* No documentation
*/
@javax.persistence.ManyToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "aCollection")
private java.util.Set<D> dCollection = new java.util.HashSet<D>();
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "a")
private java.util.Set<C> cCollection = new java.util.HashSet<C>();
public java.util.Set<B> getBCollection() {
return bCollection;
}
public void setBCollection(
java.util.Set<B> parameter) {
this.bCollection = parameter;
}
public java.util.Set<D> getDCollection() {
return dCollection;
}
public void setDCollection(
java.util.Set<D> parameter) {
this.dCollection = parameter;
}
public java.util.Set<C> getCCollection() {
return cCollection;
}
public void setCCollection(
java.util.Set<C> parameter) {
this.cCollection = parameter;
}
}

View File

@ -0,0 +1,97 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.SequenceGenerator;
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
@Id
@SequenceGenerator(name = "TIGER_GEN", sequenceName = "TIGER_SEQ")
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "TIGER_GEN")
private Long id;
@Basic
@Column(unique = true, updatable = false, length = 36, columnDefinition = "char(36)")
private String uuid;
@Column(updatable = false)
private Date created;
public AbstractEntity() {
super();
uuid = UUID.randomUUID().toString();
created = new Date();
}
public Long getId() {
return id;
}
public String getUuid() {
return uuid;
}
public Date getCreated() {
return created;
}
@Override
public int hashCode() {
return uuid == null ? 0 : uuid.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof AbstractEntity ))
return false;
final AbstractEntity other = (AbstractEntity) obj;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}
public String toString() {
if (id != null) {
return "id: '" + id + "' uuid: '" + uuid + "'";
} else {
return "id: 'transient entity' " + " uuid: '" + uuid + "'";
}
}
}

View File

@ -0,0 +1,81 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class B extends AbstractEntity {
private static final long serialVersionUID = 325417243L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "b")
private java.util.Set<C> cCollection = new java.util.HashSet<C>();
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private A a;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private F f;
public java.util.Set<C> getCCollection() {
return cCollection;
}
public void setCCollection(
java.util.Set<C> parameter) {
this.cCollection = parameter;
}
public A getA() {
return a;
}
public void setA(A parameter) {
this.a = parameter;
}
public F getF() {
return f;
}
public void setF(F parameter) {
this.f = parameter;
}
}

View File

@ -0,0 +1,80 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class C extends AbstractEntity {
private static final long serialVersionUID = 1226955752L;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private A a;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private G g;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private B b;
public A getA() {
return a;
}
public void setA(A parameter) {
this.a = parameter;
}
public G getG() {
return g;
}
public void setG(G parameter) {
this.g = parameter;
}
public B getB() {
return b;
}
public void setB(B parameter) {
this.b = parameter;
}
}

View File

@ -0,0 +1,100 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.DialectCheck;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class CascadeCircleIdentityIdTest extends BaseCoreFunctionalTestCase {
@Test
@FailureExpected( jiraKey = "HHH-5472" )
public void testCascade() {
A a = new A();
B b = new B();
C c = new C();
D d = new D();
E e = new E();
F f = new F();
G g = new G();
H h = new H();
a.getBCollection().add(b);
b.setA(a);
a.getCCollection().add(c);
c.setA(a);
b.getCCollection().add(c);
c.setB(b);
a.getDCollection().add(d);
d.getACollection().add(a);
d.getECollection().add(e);
e.setF(f);
f.getBCollection().add(b);
b.setF(f);
c.setG(g);
g.getCCollection().add(c);
f.setH(h);
h.setG(g);
Session s;
s = openSession();
s.getTransaction().begin();
try {
// Fails: says that C.b is null (even though it isn't). Doesn't fail if you persist c, g or h instead of a
s.persist(a);
s.flush();
} finally {
s.getTransaction().rollback();
s.close();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
A.class,
B.class,
C.class,
D.class,
E.class,
F.class,
G.class,
H.class
};
}
}

View File

@ -0,0 +1,66 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class D extends AbstractEntity {
private static final long serialVersionUID = 2417176961L;
/**
* No documentation
*/
@javax.persistence.ManyToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private java.util.Set<A> aCollection = new java.util.HashSet<A>();
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private java.util.Set<E> eCollection = new java.util.HashSet<E>();
public java.util.Set<A> getACollection() {
return aCollection;
}
public void setACollection(
java.util.Set<A> parameter) {
this.aCollection = parameter;
}
public java.util.Set<E> getECollection() {
return eCollection;
}
public void setECollection(
java.util.Set<E> parameter) {
this.eCollection = parameter;
}
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class E extends AbstractEntity {
private static final long serialVersionUID = 1226955558L;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private F f;
public F getF() {
return f;
}
public void setF(F parameter) {
this.f = parameter;
}
}

View File

@ -0,0 +1,65 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class F extends AbstractEntity {
private static final long serialVersionUID = 1471534025L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "f")
private java.util.Set<B> bCollection = new java.util.HashSet<B>();
/**
* No documentation
*/
@javax.persistence.OneToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private H h;
public java.util.Set<B> getBCollection() {
return bCollection;
}
public void setBCollection(
java.util.Set<B> parameter) {
this.bCollection = parameter;
}
public H getH() {
return h;
}
public void setH(H parameter) {
this.h = parameter;
}
}

View File

@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class G extends AbstractEntity {
private static final long serialVersionUID = 325417437L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "g")
private java.util.Set<C> cCollection = new java.util.HashSet<C>();
public java.util.Set<C> getCCollection() {
return cCollection;
}
public void setCCollection(
java.util.Set<C> parameter) {
this.cCollection = parameter;
}
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.identity;
/**
* No Documentation
*/
@javax.persistence.Entity
public class H extends AbstractEntity {
private static final long serialVersionUID = 1226955562L;
/**
* No documentation
*/
@javax.persistence.OneToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private G g;
public G getG() {
return g;
}
public void setG(G parameter) {
this.g = parameter;
}
}

View File

@ -0,0 +1,83 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class A extends AbstractEntity {
private static final long serialVersionUID = 864804063L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "a")
private java.util.Set<B> bCollection = new java.util.HashSet<B>();
/**
* No documentation
*/
@javax.persistence.ManyToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "aCollection")
private java.util.Set<D> dCollection = new java.util.HashSet<D>();
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "a")
private java.util.Set<C> cCollection = new java.util.HashSet<C>();
public java.util.Set<B> getBCollection() {
return bCollection;
}
public void setBCollection(
java.util.Set<B> parameter) {
this.bCollection = parameter;
}
public java.util.Set<D> getDCollection() {
return dCollection;
}
public void setDCollection(
java.util.Set<D> parameter) {
this.dCollection = parameter;
}
public java.util.Set<C> getCCollection() {
return cCollection;
}
public void setCCollection(
java.util.Set<C> parameter) {
this.cCollection = parameter;
}
}

View File

@ -0,0 +1,98 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.SequenceGenerator;
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
@Id
@SequenceGenerator(name = "TIGER_GEN", sequenceName = "TIGER_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TIGER_GEN")
private Long id;
@Basic
@Column(unique = true, updatable = false, length = 36, columnDefinition = "char(36)")
private String uuid;
@Column(updatable = false)
private Date created;
public AbstractEntity() {
super();
uuid = UUID.randomUUID().toString();
created = new Date();
}
public Long getId() {
return id;
}
public String getUuid() {
return uuid;
}
public Date getCreated() {
return created;
}
@Override
public int hashCode() {
return uuid == null ? 0 : uuid.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof AbstractEntity))
return false;
final AbstractEntity other = (AbstractEntity) obj;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}
public String toString() {
if (id != null) {
return "id: '" + id + "' uuid: '" + uuid + "'";
} else {
return "id: 'transient entity' " + " uuid: '" + uuid + "'";
}
}
}

View File

@ -0,0 +1,81 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class B extends AbstractEntity {
private static final long serialVersionUID = 325417243L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "b")
private java.util.Set<C> cCollection = new java.util.HashSet<C>();
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private org.hibernate.test.annotations.cascade.circle.sequence.A a;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private F f;
public java.util.Set<C> getCCollection() {
return cCollection;
}
public void setCCollection(
java.util.Set<C> parameter) {
this.cCollection = parameter;
}
public org.hibernate.test.annotations.cascade.circle.sequence.A getA() {
return a;
}
public void setA(org.hibernate.test.annotations.cascade.circle.sequence.A parameter) {
this.a = parameter;
}
public F getF() {
return f;
}
public void setF(F parameter) {
this.f = parameter;
}
}

View File

@ -0,0 +1,80 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class C extends AbstractEntity {
private static final long serialVersionUID = 1226955752L;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private org.hibernate.test.annotations.cascade.circle.sequence.A a;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private G g;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private org.hibernate.test.annotations.cascade.circle.sequence.B b;
public org.hibernate.test.annotations.cascade.circle.sequence.A getA() {
return a;
}
public void setA(org.hibernate.test.annotations.cascade.circle.sequence.A parameter) {
this.a = parameter;
}
public G getG() {
return g;
}
public void setG(G parameter) {
this.g = parameter;
}
public org.hibernate.test.annotations.cascade.circle.sequence.B getB() {
return b;
}
public void setB(org.hibernate.test.annotations.cascade.circle.sequence.B parameter) {
this.b = parameter;
}
}

View File

@ -0,0 +1,99 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
import org.hibernate.Session;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class CascadeCircleSequenceIdTest extends BaseCoreFunctionalTestCase {
@Test
@FailureExpected( jiraKey = "HHH-5472" )
public void testCascade() {
A a = new A();
org.hibernate.test.annotations.cascade.circle.sequence.B b = new org.hibernate.test.annotations.cascade.circle.sequence.B();
org.hibernate.test.annotations.cascade.circle.sequence.C c = new org.hibernate.test.annotations.cascade.circle.sequence.C();
D d = new D();
E e = new E();
F f = new F();
G g = new G();
H h = new H();
a.getBCollection().add(b);
b.setA(a);
a.getCCollection().add(c);
c.setA(a);
b.getCCollection().add(c);
c.setB(b);
a.getDCollection().add(d);
d.getACollection().add(a);
d.getECollection().add(e);
e.setF(f);
f.getBCollection().add(b);
b.setF(f);
c.setG(g);
g.getCCollection().add(c);
f.setH(h);
h.setG(g);
Session s;
s = openSession();
s.getTransaction().begin();
try {
// Fails: says that C.b is null (even though it isn't). Doesn't fail if you persist c, g or h instead of a
s.persist(a);
s.flush();
} finally {
s.getTransaction().rollback();
s.close();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
A.class,
org.hibernate.test.annotations.cascade.circle.sequence.B.class,
org.hibernate.test.annotations.cascade.circle.sequence.C.class,
D.class,
E.class,
F.class,
G.class,
H.class
};
}
}

View File

@ -0,0 +1,66 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class D extends AbstractEntity {
private static final long serialVersionUID = 2417176961L;
/**
* No documentation
*/
@javax.persistence.ManyToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.A> aCollection = new java.util.HashSet<org.hibernate.test.annotations.cascade.circle.sequence.A>();
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private java.util.Set<E> eCollection = new java.util.HashSet<E>();
public java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.A> getACollection() {
return aCollection;
}
public void setACollection(
java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.A> parameter) {
this.aCollection = parameter;
}
public java.util.Set<E> getECollection() {
return eCollection;
}
public void setECollection(
java.util.Set<E> parameter) {
this.eCollection = parameter;
}
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class E extends AbstractEntity {
private static final long serialVersionUID = 1226955558L;
/**
* No documentation
*/
@javax.persistence.ManyToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, optional = false)
private F f;
public F getF() {
return f;
}
public void setF(F parameter) {
this.f = parameter;
}
}

View File

@ -0,0 +1,65 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class F extends AbstractEntity {
private static final long serialVersionUID = 1471534025L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "f")
private java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.B> bCollection = new java.util.HashSet<org.hibernate.test.annotations.cascade.circle.sequence.B>();
/**
* No documentation
*/
@javax.persistence.OneToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private H h;
public java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.B> getBCollection() {
return bCollection;
}
public void setBCollection(
java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.B> parameter) {
this.bCollection = parameter;
}
public H getH() {
return h;
}
public void setH(H parameter) {
this.h = parameter;
}
}

View File

@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class G extends AbstractEntity {
private static final long serialVersionUID = 325417437L;
/**
* No documentation
*/
@javax.persistence.OneToMany(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
, mappedBy = "g")
private java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.C> cCollection = new java.util.HashSet<org.hibernate.test.annotations.cascade.circle.sequence.C>();
public java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.C> getCCollection() {
return cCollection;
}
public void setCCollection(
java.util.Set<org.hibernate.test.annotations.cascade.circle.sequence.C> parameter) {
this.cCollection = parameter;
}
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade.circle.sequence;
/**
* No Documentation
*/
@javax.persistence.Entity
public class H extends AbstractEntity {
private static final long serialVersionUID = 1226955562L;
/**
* No documentation
*/
@javax.persistence.OneToOne(cascade = {
javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH}
)
private org.hibernate.test.annotations.cascade.circle.sequence.G g;
public org.hibernate.test.annotations.cascade.circle.sequence.G getG() {
return g;
}
public void setG(org.hibernate.test.annotations.cascade.circle.sequence.G parameter) {
this.g = parameter;
}
}