Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit a9e4eb4)
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagOwner.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,38 @@ | ||
/* | ||
* 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.schemaupdate.idbag; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Andrea Boriero | ||
*/ | ||
public class IdBagOwner { | ||
private long id; | ||
private List<IdBagOwner> children = new ArrayList<IdBagOwner>(); | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public List<IdBagOwner> getChildren() { | ||
return children; | ||
} | ||
|
||
public void setChildren(List<IdBagOwner> children) { | ||
this.children = children; | ||
} | ||
|
||
public void addChild(IdBagOwner child){ | ||
children.add( child ); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/IdBagSequenceTest.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,63 @@ | ||
/* | ||
* 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.schemaupdate.idbag; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.util.EnumSet; | ||
|
||
import org.hibernate.boot.MetadataSources; | ||
import org.hibernate.boot.registry.StandardServiceRegistry; | ||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | ||
import org.hibernate.boot.spi.MetadataImplementor; | ||
import org.hibernate.cfg.Environment; | ||
import org.hibernate.tool.hbm2ddl.SchemaUpdate; | ||
import org.hibernate.tool.schema.TargetType; | ||
|
||
import org.junit.Test; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Andrea Boriero | ||
*/ | ||
@TestForIssue(jiraKey = "HHH-10373") | ||
public class IdBagSequenceTest { | ||
|
||
@Test | ||
public void testIdBagSequenceGeneratorIsCreated() throws Exception { | ||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() | ||
.applySetting( Environment.HBM2DDL_AUTO, "none" ) | ||
.build(); | ||
try { | ||
File output = File.createTempFile( "update_script", ".sql" ); | ||
output.deleteOnExit(); | ||
|
||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) | ||
.addResource( "org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml" ) | ||
.buildMetadata(); | ||
metadata.validate(); | ||
|
||
new SchemaUpdate() | ||
.setHaltOnError( true ) | ||
.setOutputFile( output.getAbsolutePath() ) | ||
.setDelimiter( ";" ) | ||
.setFormat( true ) | ||
.execute( EnumSet.of( TargetType.SCRIPT ), metadata ); | ||
|
||
String fileContent = new String( Files.readAllBytes( output.toPath() ) ); | ||
assertThat( fileContent.toLowerCase().contains( "create sequence seq_child_id" ), is( true ) ); | ||
} | ||
finally { | ||
StandardServiceRegistryBuilder.destroy( ssr ); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
hibernate-core/src/test/java/org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml
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,32 @@ | ||
<?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 PUBLIC | ||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" | ||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> | ||
|
||
<hibernate-mapping package="org.hibernate.test.schemaupdate.idbag"> | ||
|
||
<class name="org.hibernate.test.schemaupdate.idbag.IdBagOwner"> | ||
<id name="id" column="id"> | ||
<generator class="sequence"> | ||
<param name="sequence_name">seq_owner_id</param> | ||
</generator> | ||
</id> | ||
|
||
<idbag name="children" cascade="all" table="idbag_owner_children"> | ||
<collection-id type="long" column="id"> | ||
<generator class="sequence"> | ||
<param name="sequence_name">seq_child_id</param> | ||
</generator> | ||
</collection-id> | ||
<key column="PARENT_FK"/> | ||
<many-to-many column="CHILD_FK" class="org.hibernate.test.schemaupdate.idbag.IdBagOwner"/> | ||
</idbag> | ||
</class> | ||
|
||
</hibernate-mapping> |