Hibernate,多对多添加列 - StackOverFlow Exception

时间:2014-03-02 10:43:21

标签: java sql hibernate stack-overflow

我确实喜欢in this article. 第五部分将事件描述为要保留的模型。我也节省了另一个 - 就像这样:

    session.saveOrUpdate(dmodel);
    session.flush();
    session.refresh(dmodel);

在刷新操作上,我得到了StackOverFlowException。我的模型在文章中看起来很像,与其他名称字段相似,但是使用第三个表格的两个表格之间的关系结构我从本文中获取。

这是什么?如果我没有使用刷新方法 - 一切都好。

项目1:

@Entity
@Table(name = "item1")
public class Item1 implements Serializable {

   @Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
protected String uuid;

@Column(name = "name")
protected String name;

@Column
protected BigDecimal cost;

@Column(name = "description")
protected String description;

@Column(name = "add_date")
protected Date addDate;

@ManyToOne
@JoinColumn(name="category_id")
protected GiftCategory category;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.item2")
protected Set<Item1Item2> item1item2;

项目2:

@Entity
@Table(name = "item2")
public class Item1Item2 implements Serializable {

@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
protected String uuid;

@Column(name = "username")
protected String username;

@Column(name = "birth_date")
protected Date birthDate;

@Column(name = "first_name")
protected String firstName;

@Column(name = "last_name")
protected String lastName;

@Column(name = "middle_name")
protected String middleName;

@Column(name = "address")
protected String address;

@Column(name = "address_visible")
protected boolean addressVisible = false;

@Column(name = "profile_visible")
protected boolean profileVisible = true;

@Column(name = "cellPhone")
protected String cellPhone;

@Column(name = "cellPhone_visible")
protected boolean cellPhoneVisible = false;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.item1", cascade=CascadeType.ALL)
protected Set<Item1Item2> item1item2;

LinkTable:

@Entity
@Table(name = "item1_item2")
@AssociationOverrides({
    @AssociationOverride(name = "pk.item1",
            joinColumns = @JoinColumn(name = "item1_uuid")),
    @AssociationOverride(name = "pk.item2",
            joinColumns = @JoinColumn(name = "item2_uuid")) })
public class SmartUserGift implements Serializable {

@EmbeddedId
protected Item1Item2Pk pk = new Item1Item2Pk ();
}

PK LinkTable:

@Embeddable
public class Item1Item2Pk implements Serializable {
@ManyToOne
private Item1 item1;
@ManyToOne
private Item2 item2;

堆栈跟踪: 第一

SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw               exception [Request processing failed; nested exception is     org.springframework.transaction.TransactionSystemException: Could not roll back Hibernate     transaction; nested exception is org.hibernate.TransactionException: rollback failed] with     root cause
java.io.IOException: Unexpected packet type: 117
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1981)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Connection.executeTransactionCommand(AbstractJdbc2Connection.java:685)
at org.postgresql.jdbc2.AbstractJdbc2Connection.rollback(AbstractJdbc2Connection.java:738)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:163)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:209)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:574)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:846)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:823)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:493)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:264)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy42.store(Unknown Source)

第二

SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw     exception [Handler processing failed; nested exception is java.lang.StackOverflowError] with     root cause
java.lang.StackOverflowError
    at org.postgresql.jdbc2.AbstractJdbc2Statement.<init>    (AbstractJdbc2Statement.java:145)
at org.postgresql.jdbc3.AbstractJdbc3Statement.<init>(AbstractJdbc3Statement.java:42)
at org.postgresql.jdbc3g.AbstractJdbc3gStatement.<init>(AbstractJdbc3gStatement.java:28)
at org.postgresql.jdbc4.AbstractJdbc4Statement.<init>(AbstractJdbc4Statement.java:32)
at org.postgresql.jdbc4.Jdbc4Statement.<init>(Jdbc4Statement.java:30)

0 个答案:

没有答案