HHH-4851 Fix incorrect org.hibernate.PropertyValueException due to incorrect metamodel generation

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18645 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-01-27 14:31:57 +00:00
parent 75149489d5
commit ce70a30710
8 changed files with 354 additions and 2 deletions

View File

@ -162,8 +162,9 @@ public class OneToOneSecondPass implements SecondPass {
Iterator it = otherSide.getJoinIterator(); Iterator it = otherSide.getJoinIterator();
Join otherSideJoin = null; Join otherSideJoin = null;
while ( it.hasNext() ) { while ( it.hasNext() ) {
otherSideJoin = (Join) it.next(); Join otherSideJoinValue = (Join) it.next();
if ( otherSideJoin.containsProperty( otherSideProperty ) ) { if ( otherSideJoinValue.containsProperty( otherSideProperty ) ) {
otherSideJoin = otherSideJoinValue;
break; break;
} }
} }

View File

@ -0,0 +1,46 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
@MappedSuperclass
public class BaseEntity {
private Long id;
private Owner owner;
private Integer version;
@Id
@GeneratedValue
public Long getId() {
return id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "owner_id", nullable = false)
public Owner getOwner() {
return owner;
}
@Version
public Integer getVersion() {
return version;
}
public void setId(Long id) {
this.id = id;
}
public void setOwner(Owner owner) {
this.owner = owner;
}
public void setVersion(Integer version) {
this.version = version;
}
}

View File

@ -0,0 +1,37 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
@Entity
@DiscriminatorValue(value = "T")
public class Device extends Hardware {
private ManagedDevice managedDevice;
private String tag;
public Device() {
}
@OneToOne(fetch = FetchType.LAZY, mappedBy = "device")
public ManagedDevice getManagedDevice() {
return managedDevice;
}
@Column(unique = true, nullable = true)
public String getTag() {
return tag;
}
public void setManagedDevice(ManagedDevice logicalterminal) {
this.managedDevice = logicalterminal;
}
public void setTag(String tag) {
this.tag = tag;
}
}

View File

@ -0,0 +1,35 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* A group of {@link LogicalTerminal logical terminals}. Used to group them for Configuration purpose. That's why a
* LogicalTerminal can only have one TerminalGroup.
*/
@Entity
@Table
public class DeviceGroupConfig extends BaseEntity {
private String name = null;
public DeviceGroupConfig() {
}
/**
* Not unique, because we could use the same name in two different organizations.
*
* @return
*/
@Column(nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,57 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import org.hibernate.PropertyValueException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
public class HHH4851Test extends TestCase {
public void testHHH4851() throws Exception {
Session session = openSession();
Transaction trx = session.beginTransaction();
Owner org = new Owner();
org.setName( "root" );
session.saveOrUpdate( org );
ManagedDevice lTerminal = new ManagedDevice();
lTerminal.setName( "test" );
lTerminal.setOwner( org );
session.saveOrUpdate( lTerminal );
Device terminal = new Device();
terminal.setTag( "test" );
terminal.setOwner( org );
try {
session.saveOrUpdate( terminal );
}
catch ( PropertyValueException e ) {
fail( "not-null checking should not be raised: " + e.getMessage() );
}
trx.commit();
session.close();
}
@Override
protected void configure(Configuration cfg) {
super.configure( cfg );
cfg.setProperty( Environment.CHECK_NULLABILITY, "true" );
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Hardware.class,
DeviceGroupConfig.class,
Hardware.class,
ManagedDevice.class,
Device.class,
Owner.class
};
}
}

View File

@ -0,0 +1,49 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
@Entity
@Table
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "DeviceType", length = 1)
@DiscriminatorValue(value = "C")
public class Hardware extends BaseEntity {
private Hardware parent = null;
protected Hardware() {
}
public Hardware(Hardware parent) {
this.parent = parent;
}
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
public Hardware getParent() {
return this.parent;
}
public void setParent(Hardware parent) {
this.parent = parent;
}
}

View File

@ -0,0 +1,61 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* this class represents a logical representation of a terminal it could be linked to a terminal or not it contains the
* alias of the terminal and is virtualizable
*/
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }) })
public class ManagedDevice extends BaseEntity {
private String name;
private Device device;
private DeviceGroupConfig deviceGroupConfig = null;
public ManagedDevice() {
}
public ManagedDevice(String alias) {
this.name = alias;
}
public String getName() {
return name;
}
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "terminal_id")
public Device getDevice() {
return device;
}
@ManyToOne(optional = true, fetch = FetchType.LAZY)
@JoinTable(name = "ManDev_DevGroupConf",
joinColumns = { @JoinColumn(name = "MavDev_id", unique = true) },
inverseJoinColumns = { @JoinColumn(name = "DevGroupConf_id") })
public DeviceGroupConfig getDeviceGroupConfig() {
return deviceGroupConfig;
}
public void setName(String alias) {
this.name = alias;
}
public void setDevice(Device terminal) {
this.device = terminal;
}
public void setDeviceGroupConfig(DeviceGroupConfig terminalGroup) {
this.deviceGroupConfig = terminalGroup;
}
}

View File

@ -0,0 +1,66 @@
package org.hibernate.test.annotations.onetoone.hhh4851;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table
public class Owner {
private boolean deleted = false;
private Long id;
private String name;
private Integer version;
public Owner() {
}
public Owner(String name) {
this.name = name;
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
@Column(nullable = false, unique = true)
public String getName() {
return name;
}
@Version
public Integer getVersion() {
return version;
}
public boolean isDeleted() {
return deleted;
}
public Owner setDeleted(boolean isDeleted) {
this.deleted = isDeleted;
return this;
}
public void setId(Long id) {
this.id = id;
}
public Owner setName(String name) {
this.name = name;
return this;
}
public void setVersion(Integer version) {
this.version = version;
}
}