Skip to content

Commit

Permalink
HHH-10953 - Add test for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Aug 3, 2016
1 parent 7d14223 commit b900939
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
35 changes: 35 additions & 0 deletions hibernate-core/src/test/java/from/In.java
@@ -0,0 +1,35 @@
/*
* 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 from;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
* @author Andrea Boriero
*/
@Entity
public class In {
@Id
@GeneratedValue
private long id;

private String prop;

public long getId() {
return id;
}

public String getProp() {
return prop;
}

public void setProp(String prop) {
this.prop = prop;
}
}
35 changes: 35 additions & 0 deletions hibernate-core/src/test/java/in/from/Any.java
@@ -0,0 +1,35 @@
/*
* 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 in.from;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
* @author Andrea Boriero
*/
@Entity
public class Any {
@Id
@GeneratedValue
private long id;

private String prop;

public long getId() {
return id;
}

public String getProp() {
return prop;
}

public void setProp(String prop) {
this.prop = prop;
}
}
@@ -0,0 +1,128 @@
/*
* 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.hql;

import from.In;
import in.from.Any;

import org.hibernate.Session;
import org.hibernate.query.Query;
import org.hibernate.resource.transaction.spi.TransactionStatus;

import org.junit.Test;

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

/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-10953")
public class UpdateEntitiesWithPackageNamesStartingWithKeywordsTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {Any.class, In.class};
}

@Test
public void testUpdateEntityWithPackageNameStartingWithIn() {
Any entity = new Any();
entity.setProp( "1" );
try (Session session = openSession()) {

session.getTransaction().begin();
try {
session.save( entity );
session.getTransaction().commit();
}
catch (Exception e) {
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
session.getTransaction().rollback();
}
throw e;
}
}
try (Session session = openSession()) {
session.getTransaction().begin();
try {
final Query query = session.createQuery( "UPDATE Any set prop = :prop WHERE id = :id " );
query.setParameter( "prop", "1" );
query.setParameter( "id", entity.getId() );
query.executeUpdate();
session.getTransaction().commit();
}
catch (Exception e) {
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
session.getTransaction().rollback();
}
throw e;
}
}
try (Session session = openSession()) {
session.getTransaction().begin();
try {
session.createQuery( "DELETE FROM Any" ).executeUpdate();
session.getTransaction().commit();
}
catch (Exception e) {
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
session.getTransaction().rollback();
}
throw e;
}
}
}

@Test
public void testUpdateEntityWithPackageNameStartingWithFrom() {
In entity = new In();
entity.setProp( "1" );
try (Session session = openSession()) {

session.getTransaction().begin();
try {
session.save( entity );
session.getTransaction().commit();
}
catch (Exception e) {
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
session.getTransaction().rollback();
}
throw e;
}
}
try (Session session = openSession()) {
session.getTransaction().begin();
try {
final Query query = session.createQuery( "UPDATE In set prop = :prop WHERE id = :id " );
query.setParameter( "prop", "1" );
query.setParameter( "id", entity.getId() );
query.executeUpdate();
session.getTransaction().commit();
}
catch (Exception e) {
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
session.getTransaction().rollback();
}
throw e;
}
}
try (Session session = openSession()) {
session.getTransaction().begin();
try {
session.createQuery( "DELETE FROM In" ).executeUpdate();
session.getTransaction().commit();
}
catch (Exception e) {
if ( session.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
session.getTransaction().rollback();
}
throw e;
}
}
}
}

0 comments on commit b900939

Please sign in to comment.