我们更新了以下罐子 春天从3.1到4.0 Hibernate从4.1到4.3 JPA从1.0.1到2 JAVA从1.7到1.8 JBOSS 7.1.1最终到Wildfly 8服务器
我们的架构是这样的 主表(有Id) 父表(将主表的ID作为主键) 子表(将主表作为主键的ID)
以上3个表有3个单独的pojo类,并通过继承加入 父表和子表具有双向映射(一对多,多对一)
我的问题是为什么parent的findOne(Long Id)方法在升级到jar之前返回错误的子数据是正确的?
其次我们在映射中使用了DiscriminatorColumn和DiscriminatorValue但是在保存它时却无法插入异常,为什么这种行为是这样的呢?
第三个showSql = spring框架的true属性不能正常工作
我的主要表格
@Entity
@Audited
@AuditTable(value="AUDIT_PRIMARY")
@Table(name="PRIMARY")
@Inheritance(strategy = JOINED)
@DiscriminatorColumn(name = "TYPE", discriminatorType = INTEGER)
public abstract class Primary implements Serializable {
@Id
@Column(unique=true, nullable=false, precision=9)
@GeneratedValue(generator="PRIMARY_SEQ", strategy=GenerationType.SEQUENCE)
@SequenceGenerator(allocationSize=1,name="PRIMARY_SEQ", sequenceName="PRIMARY_SEQ")
private Long id;
我的父表和双向子映射
@Entity
@Audited
@AuditTable(value="AUDIT_PARENT")
@Table(name="PARENT")
@PrimaryKeyJoinColumn(name = "PARENT_ID", referencedColumnName = "ID")
@DiscriminatorValue("7")
public class Parent extends Primary implements Serializable {
@OneToMany(mappedBy="parent",cascade = CascadeType.ALL)
@AuditMappedBy(mappedBy="parent")
private List<Child> children;
我的Child表和父母的双向映射
@Entity
@Audited
@AuditTable(value="AUDIT_CHILD")
@Table(name="CHILD")
@PrimaryKeyJoinColumn(name = "CHILD_ID", referencedColumnName = "ID")
@DiscriminatorValue("6")
public class Child extends Primary implements Serializable {
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="CHILD_PARENT_ID")
private Parent parent;
我的春季配置
<tx:annotation-driven transaction-manager="transactionManager" />
<jpa:repositories base-package="com.proj.test.data.dao" entity-manager-factory- ref="entityManagerFactory" transaction-manager-ref="transactionManager" />
<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/db-ds" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dbDataSource" />
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dbDataSource" />
<property name="persistenceUnitName" value="persist" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="true" />
<property name="database" value="ORACLE" />
</bean>
</property>
</bean>