Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case for https://hibernate.atlassian.net/browse/HHH-8581 #605

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,78 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.batch.joinedInheritence;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.GenericGenerator;

/**
* @author Steve Ebersole
*/
@Entity
@Inheritance( strategy = InheritanceType.JOINED )
public class Animal {
private Long id;
private long weight;
private Long version;

@Id
@GeneratedValue( generator = "increment" )
@GenericGenerator( strategy = "increment", name = "increment" )
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Column(nullable = false)
@NotNull
@Version
public Long getVersion()
{
return version;
}

public void setVersion(Long version)
{
this.version = version;
}

public long getWeight() {
return weight;
}

public void setWeight(long weight) {
this.weight = weight;
}
}
@@ -0,0 +1,66 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.batch.joinedInheritence;

import org.hibernate.Session;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;

import org.junit.Test;

@TestForIssue( jiraKey = "HHH-8581" )
public class BatchVersionedUpdateOfJoinedHierarchyTest
extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Animal.class, Lion.class, Tiger.class, Zoo.class };
}

@Test
public void testUpdateVersionedWithWhereClause() {
Session session = openSession();
session.beginTransaction();
session.createQuery("update versioned Animal set weight = 69 where weight = 0").executeUpdate();
session.getTransaction().commit();
session.close();
}

@Test
public void testUpdateWithWhereClause() {
Session session = openSession();
session.beginTransaction();
session.createQuery("update Animal set weight = 69 where weight = 0").executeUpdate();
session.getTransaction().commit();
session.close();
}

@Test
public void testUpdateVersionedWithoutWhereClause() {
Session session = openSession();
session.beginTransaction();
session.createQuery("update versioned Animal set weight = 69").executeUpdate();
session.getTransaction().commit();
session.close();
}
}
@@ -0,0 +1,34 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.batch.joinedInheritence;

import javax.persistence.Entity;

/**
* @author Steve Ebersole
*/
@Entity
public class Lion extends Animal
{
}
@@ -0,0 +1,43 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.batch.joinedInheritence;

import javax.persistence.Entity;

/**
* @author Steve Ebersole
*/
@Entity
public class Tiger extends Animal
{
private int numberOfStripes;

public int getNumberOfStripes() {
return numberOfStripes;
}

public void setNumberOfStripes(int numberOfStripes) {
this.numberOfStripes = numberOfStripes;
}
}
@@ -0,0 +1,97 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.batch.joinedInheritence;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import org.hibernate.annotations.GenericGenerator;

/**
* @author Steve Ebersole
*/
@Entity
public class Zoo {
private Long id;
private String name;
private String city;
private Set<Tiger> tigers = new HashSet<Tiger>();
private Set<Lion> lions = new HashSet<Lion>();

@Id
@GeneratedValue( generator = "increment" )
@GenericGenerator( strategy = "increment", name = "increment" )
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 String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

@OneToMany( fetch = FetchType.EAGER ) // eager so that load-by-id queries include this association
@JoinColumn
@javax.persistence.OrderBy( "weight" )
public Set<Tiger> getTigers() {
return tigers;
}

public void setTigers(Set<Tiger> tigers) {
this.tigers = tigers;
}

@OneToMany( fetch = FetchType.EAGER ) // eager so that load-by-id queries include this association
@JoinColumn
@org.hibernate.annotations.OrderBy( clause = "weight" )
public Set<Lion> getLions() {
return lions;
}

public void setLions(Set<Lion> lions) {
this.lions = lions;
}
}