Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
...t/java/org/hibernate/test/hql/UpdateEntitiesWithPackageNamesStartingWithKeywordsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |