Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 使用sql类型字符的多列休眠一对多单向关系_Hibernate_Jpa - Fatal编程技术网

Hibernate 使用sql类型字符的多列休眠一对多单向关系

Hibernate 使用sql类型字符的多列休眠一对多单向关系,hibernate,jpa,Hibernate,Jpa,我有两个实体名为“Padre”和“Figlio” 神父是主人,菲利奥是孩子 Padre的主键有两列,PADREK1和PADREK2,都是CHAR(20) Figlio的主键有四列: PADREPADREK1(国外)字符(20) PADREPADREK2(国外)字符(20) FIGLIOK1字符(20) FIGLIOK2字符(20) 这是我的实体类的代码 public class PadreBean extends BaseEntityBean3 implements Serializable

我有两个实体名为“Padre”和“Figlio” 神父是主人,菲利奥是孩子 Padre的主键有两列,PADREK1和PADREK2,都是CHAR(20) Figlio的主键有四列: PADREPADREK1(国外)字符(20) PADREPADREK2(国外)字符(20) FIGLIOK1字符(20) FIGLIOK2字符(20)

这是我的实体类的代码

public class PadreBean extends BaseEntityBean3 implements Serializable { @EmbeddedId PadrePK iPadrePK; @Column(name = "DESCRIPTION") private String iDescription; @Column(name = "ABSUNIQUEID") private long iABSUniqueId; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns( { @JoinColumn(name = "ABSOUTQUEUENAME", nullable = true) }) private ABSOutQueueBean iAbsOutQueueBean; @OneToMany(fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn(name = "PADREPADREK1", referencedColumnName = "PADREK1"), @JoinColumn(name = "PADREPADREK2", referencedColumnName = "PADREK2") }) List iFiglioBeans; ...... 公共类PadreBean扩展BaseEntityBean3实现可序列化 { @嵌入ID PadrePK-iPadrePK; @列(name=“DESCRIPTION”) 私有字符串描述; @列(name=“ABSUNIQUEID”) 私人长假; @OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL) @连接柱( { @JoinColumn(name=“ABSOUTQUEUENAME”,nullable=true) }) 私有绝对排队bean; @OneToMany(fetch=FetchType.LAZY) @连接柱({ @JoinColumn(name=“padreparek1”,referencedColumnName=“PADREK1”), @JoinColumn(name=“padrepredek2”,referencedColumnName=“PADREK2”) }) 列出伊法利奥贝人; ...... iFiglioBeans是儿童的集合

问题是: 如果Padre的两个主键列都使用全部20个字符填充,则所有字符都可以正常工作; id padre的主键列未完全填充Hibernate加载集合 但加载后,它会清除其内容

我已激活Hibernate日志记录,当我的代码访问children集合时,我看到:

[org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost/127.0.0.1:8080-1) Obtaining JDBC connection [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost/127.0.0.1:8080-1) Obtained JDBC connection [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Result set contains (possibly empty) collection: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1, iPadreK1=p1}] [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Result set row: 0 [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Result row: EntityKey[com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=1 , iPadrePadreK1=p1 , iFiglioK1=1 , iPadrePadreK2=p1 }] [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Found row of collection: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1 , iPadreK1=p1 }] [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Result set row: 1 [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Result row: EntityKey[com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=f1 , iPadrePadreK1=p1 , iFiglioK1=f1 , iPadrePadreK2=p1 }] [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Found row of collection: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1 , iPadreK1=p1 }] [org.hibernate.engine.internal.TwoPhaseLoad] (http-localhost/127.0.0.1:8080-1) Resolving associations for [com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=1 , iPadrePadreK1=p1 , iFiglioK1=1 , iPadrePadreK2=p1 }] [org.hibernate.engine.internal.TwoPhaseLoad] (http-localhost/127.0.0.1:8080-1) Done materializing entity [com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=1 , iPadrePadreK1=p1 , iFiglioK1=1 , iPadrePadreK2=p1 }] [org.hibernate.engine.internal.TwoPhaseLoad] (http-localhost/127.0.0.1:8080-1) Resolving associations for [com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=f1 , iPadrePadreK1=p1 , iFiglioK1=f1 , iPadrePadreK2=p1 }] [org.hibernate.engine.internal.TwoPhaseLoad] (http-localhost/127.0.0.1:8080-1) Done materializing entity [com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=f1 , iPadrePadreK1=p1 , iFiglioK1=f1 , iPadrePadreK2=p1 }] [org.hibernate.engine.loading.internal.CollectionLoadContext] (http-localhost/127.0.0.1:8080-1) 2 collections were found in result set for role: com.dat.abs.run.PadreBean.iFiglioBeans [org.hibernate.engine.loading.internal.CollectionLoadContext] (http-localhost/127.0.0.1:8080-1) Collection fully initialized: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1, iPadreK1=p1}] [org.hibernate.engine.loading.internal.CollectionLoadContext] (http-localhost/127.0.0.1:8080-1) Collection fully initialized: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1 , iPadreK1=p1 }] [org.hibernate.engine.loading.internal.CollectionLoadContext] (http-localhost/127.0.0.1:8080-1) 2 collections initialized for role: com.dat.abs.run.PadreBean.iFiglioBeans [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost/127.0.0.1:8080-1) Releasing JDBC connection [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost/127.0.0.1:8080-1) Released JDBC connection [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-1) Done loading collection [org.hibernate.event.internal.AbstractFlushingEventListener] (http-localhost/127.0.0.1:8080-1) Processing flush-time cascades [org.hibernate.event.internal.AbstractFlushingEventListener] (http-localhost/127.0.0.1:8080-1) Dirty checking collections [org.hibernate.engine.internal.Collections] (http-localhost/127.0.0.1:8080-1) Collection found: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1, iPadreK1=p1}], was: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1, iPadreK1=p1}] (initialized) [org.hibernate.engine.internal.Collections] (http-localhost/127.0.0.1:8080-1) Found collection with unloaded owner: [com.dat.abs.run.PadreBean.iFiglioBeans#component[iPadreK1,iPadreK2]{iPadreK2=p1 , iPadreK1=p1 }] [org.hibernate.event.internal.AbstractFlushingEventListener] (http-localhost/127.0.0.1:8080-1) Flushed: 0 insertions, 0 updates, 0 deletions to 4 objects [org.hibernate.event.internal.AbstractFlushingEventListener] (http-localhost/127.0.0.1:8080-1) Flushed: 0 (re)creations, 0 updates, 0 removals to 2 collections [org.hibernate.internal.util.EntityPrinter] (http-localhost/127.0.0.1:8080-1) Listing entities: [org.hibernate.internal.util.EntityPrinter] (http-localhost/127.0.0.1:8080-1) com.dat.abs.run.FiglioBean{iDescrizioneFiglio= , iFiglioPK=component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=1 , iPadrePadreK1=p1 , iFiglioK1=1 , iPadrePadreK2=p1 }, iABSUniqueId=249} [org.hibernate.internal.util.EntityPrinter] (http-localhost/127.0.0.1:8080-1) com.dat.abs.run.ABSOutQueueBean{iCreationDateTime=2012-02-17 07:51:10.0, iLastUpdateUser=null, iCreationUser=system , iLastUpdateDateTime=null, iPrintServiceName=null, iId=component[iName]{iName=#01 }, iDescription=01 } [org.hibernate.internal.util.EntityPrinter] (http-localhost/127.0.0.1:8080-1) com.dat.abs.run.FiglioBean{iDescrizioneFiglio=f1 , iFiglioPK=component[iFiglioK1,iFiglioK2,iPadrePadreK1,iPadrePadreK2]{iFiglioK2=f1 , iPadrePadreK1=p1 , iFiglioK1=f1 , iPadrePadreK2=p1 }, iABSUniqueId=248} [org.hibernate.internal.util.EntityPrinter] (http-localhost/127.0.0.1:8080-1) com.dat.abs.run.PadreBean{iPadrePK=component[iPadreK1,iPadreK2]{iPadreK2=p1, iPadreK1=p1}, iAbsOutQueueBean=com.dat.abs.run.ABSOutQueueBean#component[iName]{iName=#01 }, iDescription=p1 , iABSUniqueId=247, iFiglioBeans=[]} [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost/127.0.0.1:8080-1) Releasing JDBC connection [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost/127.0.0.1:8080-1) Aggressively releasing JDBC connection [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl](http localhost/127.0.0.1:8080-1)获取jdbc连接 [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl](http localhost/127.0.0.1:8080-1)已获得jdbc连接 [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)结果集包含(可能为空)集合:[com.dat.abs.run.PadreBean.iFiglioBeans#组件[iPadreK1,iPadreK2]{iPadreK2=p1,iPadreK1=p1}] [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)结果集行:0 [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)结果行:EntityKey[com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,IPADREK1,IPADREK2]{iFiglioK2=1,IPADREK1=p1,iFiglioK1=1,IPADREK2=p1}] [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)找到集合的行:[com.dat.abs.run.PadreBean.iFiglioBeans#组件[iPadreK1,iPadreK2]{iPadreK2=p1,iPadreK1=p1}] [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)结果集行:1 [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)结果行:EntityKey[com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,IPADREK1,IPADREK2]{iFiglioK2=f1,IPADREK1=p1,iFiglioK1=f1,IPADREK2=p1}] [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)找到集合的行:[com.dat.abs.run.PadreBean.iFiglioBeans#组件[iPadreK1,iPadreK2]{iPadreK2=p1,iPadreK1=p1}] [org.hibernate.engine.internal.TwoPhaseLoad](http localhost/127.0.0.1:8080-1)解析[com.dat.abs.run.FiglioBean#组件[iFiglioK1,iFiglioK2,IPADREK1,IPADREK2]{iFiglioK2=1,IPADREK1=p1,iFiglioK1=1,IPADREK2=p1}] [org.hibernate.engine.internal.TwoPhaseLoad](http localhost/127.0.0.1:8080-1)完成实体化[com.dat.abs.run.FiglioBean#component[iFiglioK1,iFiglioK2,IPADREK1,IPADREK2]{iFiglioK2=1,IPADREK1=p1,iFiglioK1=1,IPADREK2=p1}] [org.hibernate.engine.internal.TwoPhaseLoad](http localhost/127.0.0.1:8080-1)解析[com.dat.abs.run.FiglioBean#组件[iFiglioK1,iFiglioK2,IPADREK1,IPADREK2]{iFiglioK2=f1,IPADREK1=p1,iFiglioK1=f1,IPADREK2=p1}] [org.hibernate.engine.internal.TwoPhaseLoad](http localhost/127.0.0.1:8080-1)完成实体的物化[com.dat.abs.run.FiglioBean#组件[iFiglioK1,iFiglioK2,IPADREK1,IPADREK2]{iFiglioK2=f1,IPADREK1=p1,iFiglioK1=f1,IPADREK2=p1}] [org.hibernate.engine.loading.internal.CollectionLoadContext](http localhost/127.0.0.1:8080-1)在角色的结果集中找到了2个集合:com.dat.abs.run.PadreBean.ifigliobens [org.hibernate.engine.loading.internal.CollectionLoadContext](http localhost/127.0.0.1:8080-1)集合已完全初始化:[com.dat.abs.run.PadreBean.iFiglioBeans#组件[iPadreK1,iPadreK2]{iPadreK2=p1,iPadreK1=p1}] [org.hibernate.engine.loading.internal.CollectionLoadContext](http localhost/127.0.0.1:8080-1)集合已完全初始化:[com.dat.abs.run.PadreBean.iFiglioBeans#组件[iPadreK1,iPadreK2]{iPadreK2=p1,iPadreK1=p1}] [org.hibernate.engine.loading.internal.CollectionLoadContext](http localhost/127.0.0.1:8080-1)为角色初始化的2个集合:com.dat.abs.run.PadreBean.ifigliobens [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl](http localhost/127.0.0.1:8080-1)释放jdbc连接 [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl](http localhost/127.0.0.1:8080-1)发布了jdbc连接 [org.hibernate.loader.loader](http localhost/127.0.0.1:8080-1)已完成加载集合 [org.hibernate.event.internal.AbstractFlushingEventListener](http localhost/127.0.0.1:8080-1)处理刷新时间级联 [org.hibernate.event.internal.A package com.dat.abs.run; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.usertype.UserType; public class ABSChar implements UserType { public int[] sqlTypes() { return new int[] { Types.CHAR, }; } public Class returnedClass() { return String.class; } public boolean equals(Object x, Object y) throws HibernateException { return (x == y) || (x != null && y != null && (x.equals(y))); } public Object deepCopy(Object value) throws HibernateException { if (value == null) return null; return new String((String) value); } public boolean isMutable() { return false; } @Override public int hashCode(Object aValue) throws HibernateException { return aValue.hashCode(); } @Override public Object replace(Object aOriginal, Object aTarget, Object aOwner) throws HibernateException { return aOriginal; } @Override public Object assemble(Serializable aChaced, Object aOwner) throws HibernateException { return aChaced; } @Override public Serializable disassemble(Object aValue) throws HibernateException { return (Serializable) aValue; } @Override public Object nullSafeGet(ResultSet aRs, String[] aNames, SessionImplementor aSession, Object aOwner) throws HibernateException, SQLException { String val = aRs.getString(aNames[0]); if (val == null) { return null; } return val.trim(); } @Override public void nullSafeSet(PreparedStatement aStatament, Object aValue, int aIndex, SessionImplementor aSession) throws HibernateException, SQLException { aStatament.setString(aIndex, (String) aValue); } } @Type(type = "com.dat.abs.run.ABSChar") @Column(name = "PADREPADREK1", length = 20) private String iPadrePadreK1; @Type(type = "com.dat.abs.run.ABSChar") @Column(name = "PADREPADREK2", length = 20) private String iPadrePadreK2; @Type(type = "com.dat.abs.run.ABSChar") @Column(name = "FIGLIOK1", length = 20) private String iFiglioK1; @Type(type = "com.dat.abs.run.ABSChar") @Column(name = "FIGLIOK2", length = 20)