Merge branch 'HHH-6068' of https://github.com/lukasz-antoniak/hibernate-core into lukasz-antoniak-HHH-6068

This commit is contained in:
Steve Ebersole 2011-11-28 16:17:45 -06:00
commit d00c9c85d8
5 changed files with 124 additions and 1 deletions

View File

@ -1307,10 +1307,21 @@ public class Configuration implements Serializable {
{
if ( !isDefaultProcessed ) {
//use global delimiters if orm.xml declare it
final Object isDelimited = reflectionManager.getDefaults().get( "delimited-identifier" );
Map defaults = reflectionManager.getDefaults();
final Object isDelimited = defaults.get( "delimited-identifier" );
if ( isDelimited != null && isDelimited == Boolean.TRUE ) {
getProperties().put( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
}
// Set default schema name if orm.xml declares it.
final String schema = (String) defaults.get( "schema" );
if ( StringHelper.isNotEmpty( schema ) ) {
getProperties().put( Environment.DEFAULT_SCHEMA, schema );
}
// Set default catalog name if orm.xml declares it.
final String catalog = (String) defaults.get( "catalog" );
if ( StringHelper.isNotEmpty( catalog ) ) {
getProperties().put( Environment.DEFAULT_CATALOG, catalog );
}
AnnotationBinder.bindDefaults( createMappings() );
isDefaultProcessed = true;

View File

@ -82,6 +82,8 @@ public class JPAMetadataProvider implements MetadataProvider, Serializable {
defaults = new HashMap<Object, Object>();
XMLContext.Default xmlDefaults = xmlContext.getDefault( null );
defaults.put( "schema", xmlDefaults.getSchema() );
defaults.put( "catalog", xmlDefaults.getCatalog() );
defaults.put( "delimited-identifier", xmlDefaults.getDelimitedIdentifier() );
List<Class> entityListeners = new ArrayList<Class>();
for ( String className : xmlContext.getDefaultEntityListeners() ) {

View File

@ -0,0 +1,64 @@
package org.hibernate.test.annotations.id.sequences;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.mapping.Table;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.test.annotations.id.sequences.entities.HibernateSequenceEntity;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-6068")
public class HibernateSequenceTest extends BaseCoreFunctionalTestCase {
private static final String SCHEMA_NAME = "OTHER_SCHEMA";
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
HibernateSequenceEntity.class
};
}
@Override
protected void configure(Configuration cfg) {
super.configure( cfg );
cfg.addResource( "org/hibernate/test/annotations/id/sequences/orm.xml" );
cfg.setProperty(
Environment.URL, cfg.getProperty( Environment.URL ) + ";INIT=CREATE SCHEMA IF NOT EXISTS " + SCHEMA_NAME
);
}
@Test
public void testHibernateSequenceSchema() {
EntityPersister persister = sessionFactory().getEntityPersister( HibernateSequenceEntity.class.getName() );
IdentifierGenerator generator = persister.getIdentifierGenerator();
Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
Assert.assertEquals(
Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ),
seqGenerator.getDatabaseStructure().getName()
);
}
@Test
public void testHibernateSequenceNextVal() {
Session session = openSession();
Transaction txn = session.beginTransaction();
HibernateSequenceEntity entity = new HibernateSequenceEntity();
entity.setText( "sample text" );
session.save( entity );
txn.commit();
session.close();
Assert.assertNotNull( entity.getId() );
}
}

View File

@ -0,0 +1,34 @@
package org.hibernate.test.annotations.id.sequences.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@Entity
public class HibernateSequenceEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String text;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>OTHER_SCHEMA</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>