JBPAPP-1078 EJB-413 - Removed a dependency on sequences for XMLTests and added a specific package with sequences, to be used only on databases which supports it. For trunk
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16383 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
8b4b88200b
commit
0f9a6882b9
|
@ -15,6 +15,7 @@ import javax.persistence.Persistence;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.HibernatePersistence;
|
||||
|
||||
|
||||
|
@ -146,4 +147,33 @@ public abstract class TestCase extends junit.framework.TestCase {
|
|||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runBare() throws Throwable {
|
||||
|
||||
if (!appliesTo(Dialect.getDialect()))
|
||||
return;
|
||||
|
||||
Throwable exception = null;
|
||||
setUp();
|
||||
try {
|
||||
runTest();
|
||||
} catch (Throwable running) {
|
||||
exception = running;
|
||||
} finally {
|
||||
try {
|
||||
tearDown();
|
||||
} catch (Throwable tearingDown) {
|
||||
if (exception == null)
|
||||
exception = tearingDown;
|
||||
}
|
||||
}
|
||||
if (exception != null)
|
||||
throw exception;
|
||||
}
|
||||
|
||||
public boolean appliesTo(Dialect dialect) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,18 +2,15 @@
|
|||
package org.hibernate.ejb.test.cascade;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class Author {
|
||||
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ENTITY2_SEQ")
|
||||
@SequenceGenerator(name = "ENTITY2_SEQ")
|
||||
@Id @GeneratedValue
|
||||
private Long id;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,20 +2,18 @@
|
|||
package org.hibernate.ejb.test.cascade;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class Song {
|
||||
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ENTITY1_SEQ")
|
||||
@SequenceGenerator(name = "ENTITY1_SEQ") private Long id;
|
||||
@Id @GeneratedValue
|
||||
private Long id;
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
private Author author;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
metadata-complete="false">
|
||||
<attributes>
|
||||
<id name="id">
|
||||
<generated-value strategy="SEQUENCE"/>
|
||||
<generated-value strategy="AUTO"/>
|
||||
</id>
|
||||
</attributes>
|
||||
</entity>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Address {
|
||||
private String street;
|
||||
private String city;
|
||||
private String state;
|
||||
private String zip;
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(String street, String city, String state, String zip) {
|
||||
this.street = street;
|
||||
this.city = city;
|
||||
this.state = state;
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(String zip) {
|
||||
this.zip = zip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.JoinColumn;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "ITEM")
|
||||
@org.hibernate.annotations.BatchSize(size = 10)
|
||||
public class Article {
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
private Article nextArticle;
|
||||
|
||||
@Id @GeneratedValue public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
@Column(name="poopoo")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "NEXT_MESSAGE_ID")
|
||||
public Article getNextArticle() {
|
||||
return nextArticle;
|
||||
}
|
||||
|
||||
public void setNextArticle(Article nextArticle) {
|
||||
this.nextArticle = nextArticle;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class Employee {
|
||||
@Id
|
||||
Long id;
|
||||
String name;
|
||||
/*
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "street", column = @Column(name = "HA_street")),
|
||||
@AttributeOverride(name = "city", column = @Column(name = "HA_city")),
|
||||
@AttributeOverride(name = "state", column = @Column(name = "HA_state")),
|
||||
@AttributeOverride(name = "zip", column = @Column(name = "HA_zip")) })
|
||||
*/
|
||||
Address homeAddress;
|
||||
|
||||
/*
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "street", column = @Column(name = "MA_street")),
|
||||
@AttributeOverride(name = "city", column = @Column(name = "MA_city")),
|
||||
@AttributeOverride(name = "state", column = @Column(name = "MA_state")),
|
||||
@AttributeOverride(name = "zip", column = @Column(name = "MA_zip")) })
|
||||
*/
|
||||
Address mailAddress;
|
||||
|
||||
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 Address getHomeAddress() {
|
||||
return homeAddress;
|
||||
}
|
||||
|
||||
public void setHomeAddress(Address homeAddress) {
|
||||
this.homeAddress = homeAddress;
|
||||
}
|
||||
|
||||
public Address getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
|
||||
public void setMailAddress(Address mailAddress) {
|
||||
this.mailAddress = mailAddress;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Light {
|
||||
public String name;
|
||||
public String power;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Lighter {
|
||||
public String name;
|
||||
public String power;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class XmlAttributeOverrideTest extends TestCase {
|
||||
|
||||
public void testAttributeOverriding() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Employee e = new Employee();
|
||||
e.setId(Long.valueOf(100));
|
||||
e.setName("Bubba");
|
||||
e.setHomeAddress(new Address("123 Main St", "New York", "NY", "11111"));
|
||||
e.setMailAddress(new Address("P.O. Box 123", "New York", "NY", "11111"));
|
||||
|
||||
em.persist(e);
|
||||
|
||||
em.flush();
|
||||
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getEjb3DD() {
|
||||
return new String[] {
|
||||
"org/hibernate/ejb/test/xml/sequences/orm3.xml"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
//$Id: $
|
||||
package org.hibernate.ejb.test.xml.sequences;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class XmlTest extends TestCase {
|
||||
public void testXmlMappingCorrectness() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(Dialect dialect) {
|
||||
return dialect.supportsSequences();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getEjb3DD() {
|
||||
return new String[] {
|
||||
"org/hibernate/ejb/test/xml/sequences/orm.xml",
|
||||
"org/hibernate/ejb/test/xml/sequences/orm2.xml",
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?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 orm_1_0.xsd"
|
||||
version="1.0"
|
||||
>
|
||||
<persistence-unit-metadata>
|
||||
<persistence-unit-defaults>
|
||||
<schema>MY_SCHEMA</schema>
|
||||
<catalog>MY_CATALOG</catalog>
|
||||
<access>PROPERTY</access>
|
||||
<cascade-persist/>
|
||||
</persistence-unit-defaults>
|
||||
</persistence-unit-metadata>
|
||||
<package>org.hibernate.ejb.test.xml.sequences</package>
|
||||
<entity class="Light" metadata-complete="true" access="FIELD">
|
||||
<attributes>
|
||||
<id name="name">
|
||||
<column name="fld_id"/>
|
||||
</id>
|
||||
<basic name="power"></basic>
|
||||
</attributes>
|
||||
</entity>
|
||||
<entity class="Article"
|
||||
metadata-complete="false">
|
||||
<attributes>
|
||||
<id name="id">
|
||||
<generated-value strategy="SEQUENCE"/>
|
||||
</id>
|
||||
</attributes>
|
||||
</entity>
|
||||
</entity-mappings>
|
|
@ -0,0 +1,27 @@
|
|||
<?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 orm_1_0.xsd"
|
||||
version="1.0"
|
||||
>
|
||||
<entity class="org.hibernate.ejb.test.xml.sequences.Lighter" name="ALighter" access="FIELD" metadata-complete="true">
|
||||
<attributes>
|
||||
<id name="name">
|
||||
<column name="fld_id"/>
|
||||
</id>
|
||||
<basic name="power"></basic>
|
||||
</attributes>
|
||||
</entity>
|
||||
<!-- entity class="NoPackageEntity" name="ALighter" access="FIELD" metadata-complete="true">
|
||||
<attributes>
|
||||
<id name="id"/>
|
||||
<basic name="name"/>
|
||||
</attributes>
|
||||
</entity -->
|
||||
<embeddable class="NoPackageEntity" access="FIELD">
|
||||
<attributes>
|
||||
<basic name="name"/>
|
||||
</attributes>
|
||||
</embeddable>
|
||||
</entity-mappings>
|
|
@ -0,0 +1,55 @@
|
|||
<?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_1_0.xsd"
|
||||
version="1.0">
|
||||
|
||||
<entity class="org.hibernate.ejb.test.xml.sequences.Employee" metadata-complete="false" access="FIELD">
|
||||
<attributes>
|
||||
<id name="id"/>
|
||||
<basic name="name"/>
|
||||
|
||||
<embedded name="homeAddress">
|
||||
<attribute-override name="street">
|
||||
<column name="home_street"/>
|
||||
</attribute-override>
|
||||
<attribute-override name="city">
|
||||
<column name="home_city"/>
|
||||
</attribute-override>
|
||||
<attribute-override name="state">
|
||||
<column name="home_state"/>
|
||||
</attribute-override>
|
||||
<attribute-override name="zip">
|
||||
<column name="home_zip"/>
|
||||
</attribute-override>
|
||||
</embedded>
|
||||
|
||||
<embedded name="mailAddress">
|
||||
<attribute-override name="street">
|
||||
<column name="mail_street"/>
|
||||
</attribute-override>
|
||||
<attribute-override name="city">
|
||||
<column name="mail_city"/>
|
||||
</attribute-override>
|
||||
<attribute-override name="state">
|
||||
<column name="mail_state"/>
|
||||
</attribute-override>
|
||||
<attribute-override name="zip">
|
||||
<column name="mail_zip"/>
|
||||
</attribute-override>
|
||||
</embedded>
|
||||
|
||||
</attributes>
|
||||
</entity>
|
||||
|
||||
<embeddable class="org.hibernate.ejb.test.xml.sequences.Address">
|
||||
<attributes>
|
||||
<basic name="street"/>
|
||||
<basic name="city"/>
|
||||
<basic name="state"/>
|
||||
<basic name="zip"/>
|
||||
</attributes>
|
||||
</embeddable>
|
||||
|
||||
</entity-mappings>
|
Loading…
Reference in New Issue