This commit is contained in:
Andrea Boriero 2020-02-26 09:37:19 +00:00
parent 94f23dd2d5
commit 3a9c578a14
20 changed files with 472 additions and 751 deletions

View File

@ -27,6 +27,8 @@ import javax.persistence.Transient;
import javax.persistence.TypedQuery;
import javax.persistence.Version;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
@ -35,6 +37,7 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -51,7 +54,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(
name = "AvailableSettings.MERGE_ENTITY_COPY_OBSERVER", value = "allow"
name = AvailableSettings.MERGE_ENTITY_COPY_OBSERVER, value = "allow"
)
}
)
@ -237,7 +240,7 @@ public class CascadeMergeToProxyEntityCopyAllowedTest {
})
private Project project;
@ManyToMany(targetEntity = Speaker.class, fetch = FetchType.LAZY, cascade = {
@ManyToMany(targetEntity = Speaker.class,fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST,
CascadeType.REFRESH
})

View File

@ -13,6 +13,7 @@ import java.util.Iterator;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
@ -32,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
}
)
@SessionFactory
@FailureExpected( reason = "This should be fixed by Nathan PR")
public class RefreshTest {
@Test

View File

@ -0,0 +1,223 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.manytomany;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.TypedQuery;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Andrea Boriero
*/
@DomainModel(
annotatedClasses = {
ManyToManyUnidirectionalFetchTest.Event.class,
ManyToManyUnidirectionalFetchTest.Speaker.class
}
)
@SessionFactory
public class ManyToManyUnidirectionalFetchTest {
@BeforeEach
public void setup(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Event event = new Event( 1L, "Hibernate" );
session.save( event );
}
);
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Event event = session.get( Event.class, 1L );
session.delete( event );
}
);
}
@Test
public void testJoinFetchEmptyCollection(SessionFactoryScope scope) {
scope.inTransaction(
sesison -> {
TypedQuery<Event> query = sesison.createQuery(
"SELECT e FROM Event e LEFT JOIN FETCH e.speakers WHERE e.id = :oid", Event.class );
query.setParameter( "oid", 1L );
Event event = query.getSingleResult();
assertNotNull( event );
assertEquals( 0, event.getSpeakers().size() );
}
);
}
@Test
public void testJoinEmptyCollection(SessionFactoryScope scope) {
scope.inTransaction(
sesison -> {
TypedQuery<Event> query = sesison.createQuery(
"SELECT e FROM Event e LEFT JOIN e.speakers WHERE e.id = :oid", Event.class );
query.setParameter( "oid", 1L );
Event event = query.getSingleResult();
assertNotNull( event );
Set<Speaker> speakers = event.getSpeakers();
assertEquals( 0, speakers.size() );
}
);
}
@Test
public void testJoinFetch(SessionFactoryScope scope) {
addSpeakerToEvent( scope );
scope.inTransaction(
sesison -> {
TypedQuery<Event> query = sesison.createQuery(
"SELECT e FROM Event e LEFT JOIN FETCH e.speakers WHERE e.id = :oid", Event.class );
query.setParameter( "oid", 1L );
Event event = query.getSingleResult();
assertNotNull( event );
Set<Speaker> speakers = event.getSpeakers();
assertEquals( 1, speakers.size() );
assertThat( speakers.iterator().next().getName(), is( "Steve" ) );
}
);
}
@Test
public void testJoin(SessionFactoryScope scope) {
addSpeakerToEvent( scope );
scope.inTransaction(
sesison -> {
TypedQuery<Event> query = sesison.createQuery(
"SELECT e FROM Event e LEFT JOIN e.speakers WHERE e.id = :oid", Event.class );
query.setParameter( "oid", 1L );
Event event = query.getSingleResult();
assertNotNull( event );
Set<Speaker> speakers = event.getSpeakers();
assertEquals( 1, speakers.size() );
assertThat( speakers.iterator().next().getName(), is( "Steve" ) );
}
);
}
private void addSpeakerToEvent(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Event event = session.get( Event.class, 1l );
Speaker speaker = new Speaker( 2l, "Steve" );
event.addSpeaker( speaker );
session.save( speaker );
}
);
}
@Entity(name = "Event")
public static class Event {
@Id
private Long id;
private String name;
public Event() {
}
public Event(Long id, String name) {
this.id = id;
this.name = name;
}
@ManyToMany(targetEntity = Speaker.class, fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST,
CascadeType.REFRESH,
CascadeType.REMOVE
})
private Set<Speaker> speakers = new HashSet<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Speaker> getSpeakers() {
return Collections.unmodifiableSet( speakers );
}
public void setSpeakers(Set<Speaker> speakers) {
this.speakers = speakers;
}
public void addSpeaker(Speaker speaker) {
this.speakers.add( speaker );
}
}
@Entity(name = "Speaker")
public static class Speaker {
@Id
private Long id;
private String name;
public Speaker() {
}
public Speaker(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -0,0 +1,242 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.onetomany;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.TypedQuery;
import org.hibernate.Hibernate;
import org.hibernate.collection.internal.PersistentSet;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Andrea Boriero
*/
@DomainModel(
annotatedClasses = {
OneToManySelfReferenceTest.Event.class
}
)
@SessionFactory
public class OneToManySelfReferenceTest {
@BeforeEach
public void setUp(SessionFactoryScope scope) {
Event parent = new Event();
scope.inTransaction(
session -> {
parent.setName( "parent" );
parent.setId( 1L );
Event child = new Event();
child.setId( 2L );
child.setName( "child" );
parent.addChid( child );
session.save( parent );
session.save( child );
}
);
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session ->
session.createQuery( "delete from Event" ).executeUpdate()
);
}
@Test
public void testSelectParentFetchChildren(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
TypedQuery<Event> eventTypedQuery = session.createQuery(
"SELECT e FROM Event e left join fetch e.children WHERE e.id = :oid",
Event.class
);
eventTypedQuery.setParameter( "oid", 1L );
Event event = eventTypedQuery.getSingleResult();
Set<Event> children = event.getChildren();
assertTrue(
Hibernate.isInitialized( children ),
"Children collection has not been initialized"
);
assertThat( children.size(), is( 1 ) );
assertThat( children, instanceOf( PersistentSet.class ) );
PersistentSet persistentSet = (PersistentSet) children;
assertThat( persistentSet.getKey(), is(1L) );
Event child = children.iterator().next();
Set<Event> childChildren = child.getChildren();
assertFalse(
Hibernate.isInitialized( childChildren ),
"Child children collection should not be initialized"
);
assertThat( childChildren, instanceOf( PersistentSet.class ) );
PersistentSet childChildrenPersistentSet = (PersistentSet) childChildren;
assertThat( childChildrenPersistentSet.getKey(), is(2L) );
assertThat( childChildren.size(), is(0) );
assertTrue(
Hibernate.isInitialized( childChildren ),
"Child children collection should not be initialized"
);
}
);
}
@Test
public void testSelectParent(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
TypedQuery<Event> eventTypedQuery = session.createQuery(
"SELECT e FROM Event e WHERE e.id = :oid",
Event.class
);
eventTypedQuery.setParameter( "oid", 1L );
Event event = eventTypedQuery.getSingleResult();
Set<Event> children = event.getChildren();
assertFalse(
Hibernate.isInitialized( children ),
"Children collection should not be initialized"
);
assertThat( children.size(), is( 1 ) );
assertTrue(
Hibernate.isInitialized( children ),
"Children collection has not been initialized"
);
Event child = children.iterator().next();
Set<Event> childChildren = child.getChildren();
assertFalse(
Hibernate.isInitialized( childChildren ),
"Child children collection should not be initialized"
);
assertThat( childChildren, instanceOf( PersistentSet.class ) );
PersistentSet childChildrenPersistentSet = (PersistentSet) childChildren;
assertThat( childChildrenPersistentSet.getKey(), is(2L) );
assertThat( childChildren.size(), is(0) );
}
);
}
@Test
public void testSelectChild(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
TypedQuery<Event> eventTypedQuery = session.createQuery(
"SELECT e FROM Event e left join fetch e.children WHERE e.id = :oid",
Event.class
);
eventTypedQuery.setParameter( "oid", 2L );
Event event = eventTypedQuery.getSingleResult();
Set<Event> children = event.getChildren();
assertTrue(
Hibernate.isInitialized( children ),
"Children collection has not been initialized"
);
assertThat( children.size(), is( 0 ) );
assertThat( children, instanceOf( PersistentSet.class ) );
PersistentSet childrenPersistentSet = (PersistentSet) children;
assertThat( childrenPersistentSet.getKey(), is(2L) );
Event parent = event.getParent();
assertThat( parent.getId(), is(1L) );
Set<Event> parentChildren = parent.getChildren();
assertFalse(
Hibernate.isInitialized( parentChildren ),
"Child children collection should not be initialized"
);
PersistentSet parentChildrenPersistentSet = (PersistentSet) parentChildren;
assertThat( parentChildrenPersistentSet.getKey(), is(1L) );
Event next = parentChildren.iterator().next();
assertThat( next, sameInstance(event) );
}
);
}
@Entity(name = "Event")
public static class Event {
private Long id;
private String name;
private Event parent;
private Set<Event> children = new HashSet<>();
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne(targetEntity = Event.class)
public Event getParent() {
return parent;
}
public void setParent(Event parent) {
this.parent = parent;
}
@OneToMany(targetEntity = Event.class, mappedBy = "parent")
public Set<Event> getChildren() {
return children;
}
public void setChildren(Set<Event> children) {
this.children = children;
}
public void addChid(Event event) {
this.children.add( event );
event.setParent( this );
}
}
}

View File

@ -1,104 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.cascade;
import java.util.HashSet;
import java.util.Set;
public class A
{
// Constants -----------------------------------------------------------------------------------
// Static --------------------------------------------------------------------------------------
// Attributes ----------------------------------------------------------------------------------
private long id;
private String data;
// A 1 - * H
private Set hs;
// A 1 - 1 G
private G g;
// Constructors --------------------------------------------------------------------------------
public A()
{
hs = new HashSet();
}
public A(String data)
{
this();
this.data = data;
}
// Public --------------------------------------------------------------------------------------
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public void setData(String data)
{
this.data = data;
}
public String getData()
{
return data;
}
public void setHs(Set hs)
{
this.hs = hs;
}
public Set getHs()
{
return hs;
}
public void setG(G g)
{
this.g = g;
}
public G getG()
{
return g;
}
public void addH(H h)
{
hs.add(h);
h.setA(this);
}
public String toString()
{
return "A[" + id + ", " + data + "]";
}
// Package protected ---------------------------------------------------------------------------
// Protected -----------------------------------------------------------------------------------
// Private -------------------------------------------------------------------------------------
// Inner classes -------------------------------------------------------------------------------
}

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="Child" table="Child">
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<many-to-one name="parent" class="Parent" not-null="false" cascade="all"/>
</class>
</hibernate-mapping>

View File

@ -1,36 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.cascade;
/**
* Created by IntelliJ IDEA.
* User: Gail
* Date: Jan 2, 2007
* Time: 4:51:29 PM
* To change this template use File | Settings | File Templates.
*/
public class Child {
private Long id;
private Parent parent;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="Child" table="Child">
<id name="id" column="id" type="java.lang.Long">
<generator class="native"/>
</id>
<many-to-one name="parent" class="Parent" not-null="true" cascade="all" />
</class>
</hibernate-mapping>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="DeleteOrphanChild" table="DeleteOrphanChild">
<id name="id" column="id" type="java.lang.Long">
<generator class="native"/>
</id>
<many-to-one name="parent" class="Parent" not-null="false" cascade="all"/>
</class>
</hibernate-mapping>

View File

@ -1,36 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.cascade;
/**
* Created by IntelliJ IDEA.
* User: Gail
* Date: Jan 2, 2007
* Time: 4:52:10 PM
* To change this template use File | Settings | File Templates.
*/
public class DeleteOrphanChild {
private Long id;
private Parent parent;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}

View File

@ -1,95 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id: $
package org.hibernate.test.cascade;
import java.util.HashSet;
import java.util.Set;
public class G
{
// Constants -----------------------------------------------------------------------------------
// Static --------------------------------------------------------------------------------------
// Attributes ----------------------------------------------------------------------------------
private long id;
private String data;
// A 1 <-> 1 G
private A a;
// G * <-> * H
private Set hs;
// Constructors --------------------------------------------------------------------------------
public G()
{
this(null);
}
public G(String data)
{
this.data = data;
hs = new HashSet();
}
// Public --------------------------------------------------------------------------------------
public String getData()
{
return data;
}
public void setData(String data)
{
this.data = data;
}
public A getA()
{
return a;
}
public void setA(A a)
{
this.a = a;
}
public Set getHs()
{
return hs;
}
public void setHs(Set s)
{
hs = s;
}
// Package protected ---------------------------------------------------------------------------
long getId()
{
return id;
}
// Protected -----------------------------------------------------------------------------------
// Private -------------------------------------------------------------------------------------
private void setId(long id)
{
this.id = id;
}
// Inner classes -------------------------------------------------------------------------------
}

View File

@ -1,94 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id: $
package org.hibernate.test.cascade;
import java.util.HashSet;
import java.util.Set;
public class H
{
// Constants -----------------------------------------------------------------------------------
// Static --------------------------------------------------------------------------------------
// Attributes ----------------------------------------------------------------------------------
private long id;
private String data;
private A a;
// G * <-> * H
private Set gs;
// Constructors --------------------------------------------------------------------------------
public H()
{
this(null);
}
public H(String data)
{
this.data = data;
gs = new HashSet();
}
// Public --------------------------------------------------------------------------------------
public long getId()
{
return id;
}
public String getData()
{
return data;
}
public void setData(String data)
{
this.data = data;
}
public A getA()
{
return a;
}
public void setA(A a)
{
this.a = a;
}
public Set getGs()
{
return gs;
}
public void setGs(Set gs)
{
this.gs = gs;
}
// Package protected ---------------------------------------------------------------------------
// Protected -----------------------------------------------------------------------------------
// Private -------------------------------------------------------------------------------------
private void setId(long id)
{
this.id = id;
}
// Inner classes -------------------------------------------------------------------------------
}

View File

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="Job" table="T_JOB">
<id name="id" column="JOB_ID">
<generator class="native"/>
</id>
<many-to-one name="batch" class="JobBatch" cascade="none" column="BATCH_ID"/>
<property name="status" type="int" column="JOB_STATUS" not-null="true"/>
<property name="processingInstructions" type="string" column="PI" not-null="true"/>
</class>
</hibernate-mapping>

View File

@ -1,61 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
// $Id: Job.java 6663 2005-05-03 20:55:31Z steveebersole $
package org.hibernate.test.cascade;
/**
* Implementation of Job.
*
* @author Steve Ebersole
*/
public class Job {
private Long id;
private JobBatch batch;
private String processingInstructions;
private int status;
/** GCLIB constructor */
Job() {}
protected Job(JobBatch batch) {
this.batch = batch;
}
public Long getId() {
return id;
}
/*package*/ void setId(Long id) {
this.id = id;
}
public JobBatch getBatch() {
return batch;
}
/*package*/ void setBatch(JobBatch batch) {
this.batch = batch;
}
public String getProcessingInstructions() {
return processingInstructions;
}
public void setProcessingInstructions(String processingInstructions) {
this.processingInstructions = processingInstructions;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}

View File

@ -1,26 +0,0 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="JobBatch" table="T_JOB_BATCH">
<id name="id" column="BATCH_ID">
<generator class="native"/>
</id>
<property name="batchDate" type="timestamp" column="BATCH_DATE" not-null="true"/>
<set name="jobs" inverse="true" fetch="select" lazy="true" cascade="all, refresh">
<key column="BATCH_ID"/>
<one-to-many class="Job"/>
</set>
</class>
</hibernate-mapping>

View File

@ -1,60 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
// $Id: JobBatch.java 6663 2005-05-03 20:55:31Z steveebersole $
package org.hibernate.test.cascade;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* Implementation of JobBatch.
*
* @author Steve Ebersole
*/
public class JobBatch {
private Long id;
private Date batchDate;
private Set jobs = new HashSet();
/** CGLIB constructor */
JobBatch() {}
public JobBatch(Date batchDate) {
this.batchDate = batchDate;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getBatchDate() {
return batchDate;
}
public void setBatchDate(Date batchDate) {
this.batchDate = batchDate;
}
public Set getJobs() {
return jobs;
}
public void setJobs(Set jobs) {
this.jobs = jobs;
}
public Job createJob() {
Job job = new Job( this );
jobs.add( job );
return job;
}
}

View File

@ -1,73 +0,0 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="A" table="HB_A">
<id name="id" type="long"><generator class="native"/></id>
<property name="data" column="`data`" type="string" not-null="true"/>
<!--
Associations
-->
<set name="hs" inverse="true" cascade="all">
<key column="a_fk"/>
<one-to-many class="H"/>
</set>
<one-to-one name="g" class="G" property-ref="a" cascade="all"/>
</class>
<class name="G" table="HB_G">
<id name="id" type="long"><generator class="native"/></id>
<property name="data" column="`data`" type="string" not-null="true"/>
<!--
Associations
-->
<set name="hs" inverse="true" table="HB_G_H" cascade="all">
<key column="g_fk"/>
<many-to-many class="H" column="h_fk"/>
</set>
<many-to-one name="a"
column="aId"
unique="true"
not-null="false"/>
</class>
<class name="H" table="HB_H">
<id name="id" type="long"><generator class="native"/></id>
<property name="data" column="`data`" type="string" not-null="true"/>
<!--
Associations
-->
<!-- *NOT* cascaded -->
<set name="gs" table="HB_G_H">
<key column="h_fk"/>
<many-to-many class="G" column="g_fk"/>
</set>
<many-to-one name="a" column="a_fk" class="A"/>
</class>
</hibernate-mapping>

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="Parent" table="Parent">
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<set name="children" cascade="all" inverse="true">
<key column="parent"/>
<one-to-many class="Child"/>
</set>
<set name="deleteOrphanChildren" cascade="all-delete-orphan" inverse="true">
<key column="parent"/>
<one-to-many class="DeleteOrphanChild"/>
</set>
</class>
</hibernate-mapping>

View File

@ -1,45 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.cascade;
import java.util.Set;
/**
* Created by IntelliJ IDEA.
* User: Gail
* Date: Jan 2, 2007
* Time: 4:50:24 PM
* To change this template use File | Settings | File Templates.
*/
public class Parent {
private Long id;
private Set deleteOrphanChildren;
private Set children;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set getDeleteOrphanChildren() {
return deleteOrphanChildren;
}
public void setDeleteOrphanChildren(Set deleteOrphanChildren) {
this.deleteOrphanChildren = deleteOrphanChildren;
}
public Set getChildren() {
return children;
}
public void setChildren(Set children) {
this.children = children;
}
}

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.cascade">
<class name="Parent" table="Parent">
<id name="id" column="id" type="java.lang.Long">
<generator class="assigned"/>
</id>
<set name="children" cascade="all" inverse="true">
<key column="parent"/>
<one-to-many class="Child"/>
</set>
</class>
</hibernate-mapping>