HHH-4889 if the @IdClass support the legacy approach ie the reference to the association in the IdClass (as opposed to its pk), treat it the old way
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18732 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
817fe52a55
commit
7373796908
|
@ -2201,8 +2201,11 @@ public final class
|
|||
+ idClassPropertyData.getPropertyName()
|
||||
);
|
||||
}
|
||||
if ( entityPropertyData.getProperty().isAnnotationPresent( ManyToOne.class )
|
||||
|| entityPropertyData.getProperty().isAnnotationPresent( OneToOne.class ) ) {
|
||||
final boolean hasXToOneAnnotation = entityPropertyData.getProperty()
|
||||
.isAnnotationPresent( ManyToOne.class )
|
||||
|| entityPropertyData.getProperty().isAnnotationPresent( OneToOne.class );
|
||||
final boolean isOfDifferentType = ! entityPropertyData.getClassOrElement().equals( idClassPropertyData.getClassOrElement() );
|
||||
if ( hasXToOneAnnotation && isOfDifferentType ) {
|
||||
//don't replace here as we need to use the actual original return type
|
||||
//the annotation overriding will be dealt with by a mechanism similar to @MapsId
|
||||
}
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.complex;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@NamedQueries({
|
||||
@NamedQuery(name="CustomerInventory.selectAll",
|
||||
query="select a from CustomerInventory a")
|
||||
})
|
||||
@SuppressWarnings("serial")
|
||||
@Entity
|
||||
@Table(name="O_CUSTINVENTORY")
|
||||
@IdClass(CustomerInventoryPK.class)
|
||||
public class CustomerInventory implements Serializable, Comparator<CustomerInventory> {
|
||||
|
||||
@Id
|
||||
@TableGenerator(name="inventory",
|
||||
table="U_SEQUENCES",
|
||||
pkColumnName="S_ID",
|
||||
valueColumnName="S_NEXTNUM",
|
||||
pkColumnValue="inventory",
|
||||
allocationSize=1000)
|
||||
@GeneratedValue(strategy=GenerationType.TABLE,generator="inventory")
|
||||
@Column(name="CI_ID")
|
||||
private Integer id;
|
||||
|
||||
|
||||
@Id
|
||||
@ManyToOne(cascade=CascadeType.MERGE)
|
||||
@JoinColumn(name="CI_CUSTOMERID")
|
||||
private Customer customer;
|
||||
|
||||
@ManyToOne(cascade=CascadeType.MERGE)
|
||||
@JoinColumn(name = "CI_ITEMID")
|
||||
private Item vehicle;
|
||||
|
||||
@Column(name="CI_VALUE")
|
||||
private BigDecimal totalCost;
|
||||
|
||||
@Column(name="CI_QUANTITY")
|
||||
private int quantity;
|
||||
|
||||
@Version
|
||||
@Column(name = "CI_VERSION")
|
||||
private int version;
|
||||
|
||||
protected CustomerInventory() {
|
||||
}
|
||||
|
||||
CustomerInventory(Customer customer, Item vehicle, int quantity , BigDecimal totalValue)
|
||||
{
|
||||
this.customer = customer;
|
||||
this.vehicle = vehicle;
|
||||
this.quantity = quantity;
|
||||
this.totalCost = totalValue;
|
||||
}
|
||||
|
||||
public Item getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalCost() {
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public int compare(CustomerInventory cdb1, CustomerInventory cdb2) {
|
||||
return cdb1.id.compareTo(cdb2.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj == null || !(obj instanceof CustomerInventory))
|
||||
return false;
|
||||
if (this.id == ((CustomerInventory)obj).id)
|
||||
return true;
|
||||
if (this.id != null && ((CustomerInventory)obj).id == null)
|
||||
return false;
|
||||
if (this.id == null && ((CustomerInventory)obj).id != null)
|
||||
return false;
|
||||
|
||||
return this.id.equals(((CustomerInventory)obj).id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.complex;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class CustomerInventoryPK implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Customer customer;
|
||||
|
||||
public CustomerInventoryPK() {
|
||||
}
|
||||
|
||||
public CustomerInventoryPK(Integer id, Customer customer) {
|
||||
this.id = id;
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
CustomerInventoryPK cip = (CustomerInventoryPK) other;
|
||||
return (getCustomer().getId() == cip.getCustomer().getId() && (id == cip.id ||
|
||||
( id != null && id.equals(cip.id))));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (id == null ? 0 : id.hashCode()) ^ getCustomer().getId();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.complex;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
|
||||
import org.hibernate.junit.FailureExpected;
|
||||
/**
|
||||
* A test.
|
||||
*
|
||||
* @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public class IdClassGeneratedValueManyToOneTest extends TestCase
|
||||
{
|
||||
@FailureExpected(jiraKey="HHH-4848")
|
||||
public void testComplexIdClass()
|
||||
{
|
||||
Logger.getLogger("org.hibernate").setLevel(Level.TRACE);
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Customer c1 = new Customer("foo", "bar", "contact1", "100", new BigDecimal(1000),new BigDecimal(1000), new BigDecimal(1000));
|
||||
|
||||
s.persist(c1);
|
||||
Item boat = new Item();
|
||||
boat.setId("1");
|
||||
boat.setName("cruiser");
|
||||
boat.setPrice(new BigDecimal(500));
|
||||
boat.setDescription("a boat");
|
||||
boat.setCategory(42);
|
||||
|
||||
s.persist(boat);
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
c1.addInventory(boat, 10, new BigDecimal(5000));
|
||||
s.merge(c1);
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
Customer c2 = (Customer) s.createQuery( "select c from Customer c" ).uniqueResult();
|
||||
|
||||
List<CustomerInventory> inventory = c2.getInventories();
|
||||
|
||||
assertEquals(1, inventory.size());
|
||||
assertEquals(10, inventory.get(0).getQuantity());
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
protected Class[] getAnnotatedClasses()
|
||||
{
|
||||
return new Class[] {
|
||||
Customer.class,
|
||||
CustomerInventory.class,
|
||||
CustomerInventoryPK.class,
|
||||
Item.class
|
||||
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.complex;
|
||||
package org.hibernate.test.annotations.derivedidentities.e1.b2;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -6,11 +6,8 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
|
@ -0,0 +1,122 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e1.b2;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "CustomerInventory.selectAll",
|
||||
query = "select a from CustomerInventory a")
|
||||
})
|
||||
@SuppressWarnings("serial")
|
||||
@Entity
|
||||
@Table(name = "O_CUSTINVENTORY")
|
||||
@IdClass(CustomerInventoryPK.class)
|
||||
public class CustomerInventory implements Serializable, Comparator<CustomerInventory> {
|
||||
|
||||
@Id
|
||||
@TableGenerator(name = "inventory",
|
||||
table = "U_SEQUENCES",
|
||||
pkColumnName = "S_ID",
|
||||
valueColumnName = "S_NEXTNUM",
|
||||
pkColumnValue = "inventory",
|
||||
allocationSize = 1000)
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "inventory")
|
||||
@Column(name = "CI_ID")
|
||||
private Integer id;
|
||||
|
||||
|
||||
@Id
|
||||
@ManyToOne(cascade = CascadeType.MERGE)
|
||||
@JoinColumn(name = "CI_CUSTOMERID")
|
||||
private Customer customer;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.MERGE)
|
||||
@JoinColumn(name = "CI_ITEMID")
|
||||
private Item vehicle;
|
||||
|
||||
@Column(name = "CI_VALUE")
|
||||
private BigDecimal totalCost;
|
||||
|
||||
@Column(name = "CI_QUANTITY")
|
||||
private int quantity;
|
||||
|
||||
@Version
|
||||
@Column(name = "CI_VERSION")
|
||||
private int version;
|
||||
|
||||
protected CustomerInventory() {
|
||||
}
|
||||
|
||||
CustomerInventory(Customer customer, Item vehicle, int quantity, BigDecimal totalValue) {
|
||||
this.customer = customer;
|
||||
this.vehicle = vehicle;
|
||||
this.quantity = quantity;
|
||||
this.totalCost = totalValue;
|
||||
}
|
||||
|
||||
public Item getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalCost() {
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public int compare(CustomerInventory cdb1, CustomerInventory cdb2) {
|
||||
return cdb1.id.compareTo( cdb2.id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( obj == this ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null || !( obj instanceof CustomerInventory ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( this.id == ( ( CustomerInventory ) obj ).id ) {
|
||||
return true;
|
||||
}
|
||||
if ( this.id != null && ( ( CustomerInventory ) obj ).id == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( this.id == null && ( ( CustomerInventory ) obj ).id != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.id.equals( ( ( CustomerInventory ) obj ).id );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e1.b2;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class CustomerInventoryPK implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Customer customer;
|
||||
|
||||
public CustomerInventoryPK() {
|
||||
}
|
||||
|
||||
public CustomerInventoryPK(Integer id, Customer customer) {
|
||||
this.id = id;
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if ( other == this ) {
|
||||
return true;
|
||||
}
|
||||
if ( other == null || getClass() != other.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
CustomerInventoryPK cip = ( CustomerInventoryPK ) other;
|
||||
return ( getCustomer().getId() == cip.getCustomer().getId() && ( id == cip.id ||
|
||||
( id != null && id.equals( cip.id ) ) ) );
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ( id == null ? 0 : id.hashCode() ) ^ getCustomer().getId();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e1.b2;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.junit.FailureExpected;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
|
||||
/**
|
||||
* A test.
|
||||
*
|
||||
* @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public class IdClassGeneratedValueManyToOneTest extends TestCase {
|
||||
|
||||
@FailureExpected(jiraKey="HHH-4890")
|
||||
public void testComplexIdClass() {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Customer c1 = new Customer(
|
||||
"foo", "bar", "contact1", "100", new BigDecimal( 1000 ), new BigDecimal( 1000 ), new BigDecimal( 1000 )
|
||||
);
|
||||
|
||||
s.persist( c1 );
|
||||
Item boat = new Item();
|
||||
boat.setId( "1" );
|
||||
boat.setName( "cruiser" );
|
||||
boat.setPrice( new BigDecimal( 500 ) );
|
||||
boat.setDescription( "a boat" );
|
||||
boat.setCategory( 42 );
|
||||
|
||||
s.persist( boat );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
c1.addInventory( boat, 10, new BigDecimal( 5000 ) );
|
||||
s.merge( c1 );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
Customer c2 = ( Customer ) s.createQuery( "select c from Customer c" ).uniqueResult();
|
||||
|
||||
List<CustomerInventory> inventory = c2.getInventories();
|
||||
|
||||
assertEquals( 1, inventory.size() );
|
||||
assertEquals( 10, inventory.get( 0 ).getQuantity() );
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
|
||||
assertTrue( true );
|
||||
}
|
||||
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Customer.class,
|
||||
CustomerInventory.class,
|
||||
CustomerInventoryPK.class,
|
||||
Item.class
|
||||
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.complex;
|
||||
package org.hibernate.test.annotations.derivedidentities.e1.b2;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
Loading…
Reference in New Issue