我已将Hibernate缓存从EHCache切换到Infinispan,现在在修改具有复合主键的实体时遇到异常。实体如下:
@Entity
@Table(name="Company_Message_Type")
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class CompanyMessageType implements Serializable
{
private static final long serialVersionUID = 1L;
@EmbeddedId private final CompanyMessageTypeId id = new CompanyMessageTypeId();
@Column(name="FL_EXTERNAL_ACCESS", nullable=false)
private boolean externalAccess;
@Column(name="FL_VIEW_CONTENT", nullable=false)
private boolean viewContent;
@MapsId("companyId")
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_COMPANY", nullable=false)
private Company company;
@MapsId("messageTypeId")
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_MESSAGE_TYPE", nullable=false)
private MessageType messageType;
}
嵌入式Id类如下:
@Embeddable
public class CompanyMessageTypeId implements Serializable
{
private static final long serialVersionUID = 1L;
@Column(name="ID_COMPANY", nullable=false)
private Long companyId;
@Column(name="ID_MESSAGE_TYPE", nullable=false)
private Long messageTypeId;
}
这两个类都有合理的方法。
只有当集群中有多个服务器时,才会发生异常。异常出现在正在更新的服务器上。堆栈跟踪如下:
ISPN000220: Problems un-marshalling remote command from byte buffer
java.io.InvalidObjectException: Could not find a SessionFactory [uuid=0d0cdf26-dfe6-4285-9725-dfaa4821ecba,name=null]
at org.hibernate.internal.SessionFactoryImpl.locateSessionFactoryOnDeserialization(SessionFactoryImpl.java:1781)
at org.hibernate.internal.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:1761)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jboss.marshalling.reflect.SerializableClass.callReadResolve(SerializableClass.java:413)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1270)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1711)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1627)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1269)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1711)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1627)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1591)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1269)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1711)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1627)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1269)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readParameters(ReplicableCommandExternalizer.java:100)
at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readObject(ReplicableCommandExternalizer.java:83)
at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readObject(ReplicableCommandExternalizer.java:30)
at org.infinispan.marshall.core.ExternalizerTable$ExternalizerAdapter.readObject(ExternalizerTable.java:389)
at org.infinispan.marshall.core.ExternalizerTable.readObject(ExternalizerTable.java:205)
at org.infinispan.marshall.core.JBossMarshaller$ExternalizerTableProxy.readObject(JBossMarshaller.java:152)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:351)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readParameters(ReplicableCommandExternalizer.java:100)
at org.infinispan.marshall.exts.CacheRpcCommandExternalizer.readObject(CacheRpcCommandExternalizer.java:146)
at org.infinispan.marshall.exts.CacheRpcCommandExternalizer.readObject(CacheRpcCommandExternalizer.java:59)
at org.infinispan.marshall.core.ExternalizerTable$ExternalizerAdapter.readObject(ExternalizerTable.java:389)
at org.infinispan.marshall.core.ExternalizerTable.readObject(ExternalizerTable.java:205)
at org.infinispan.marshall.core.JBossMarshaller$ExternalizerTableProxy.readObject(JBossMarshaller.java:152)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:351)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.infinispan.commons.marshall.jboss.AbstractJBossMarshaller.objectFromObjectStream(AbstractJBossMarshaller.java:136)
at org.infinispan.marshall.core.VersionAwareMarshaller.objectFromByteBuffer(VersionAwareMarshaller.java:101)
at org.infinispan.commons.marshall.AbstractDelegatingMarshaller.objectFromByteBuffer(AbstractDelegatingMarshaller.java:80)
at org.infinispan.remoting.transport.jgroups.MarshallerAdapter.objectFromBuffer(MarshallerAdapter.java:28)
at org.infinispan.remoting.transport.jgroups.CommandAwareRpcDispatcher.handle(CommandAwareRpcDispatcher.java:206)
at org.jgroups.blocks.RequestCorrelator.handleRequest(RequestCorrelator.java:460)
at org.jgroups.blocks.RequestCorrelator.receiveMessage(RequestCorrelator.java:377)
at org.jgroups.blocks.RequestCorrelator.receive(RequestCorrelator.java:247)
at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.up(MessageDispatcher.java:665)
at org.jgroups.JChannel.up(JChannel.java:708)
at org.jgroups.stack.ProtocolStack.up(ProtocolStack.java:1015)
at org.jgroups.protocols.RSVP.up(RSVP.java:187)
at org.jgroups.protocols.FRAG2.up(FRAG2.java:165)
at org.jgroups.protocols.FlowControl.up(FlowControl.java:381)
at org.jgroups.protocols.FlowControl.up(FlowControl.java:370)
at org.jgroups.protocols.tom.TOA.up(TOA.java:121)
at org.jgroups.protocols.pbcast.GMS.up(GMS.java:1010)
at org.jgroups.protocols.pbcast.STABLE.up(STABLE.java:234)
at org.jgroups.protocols.AUTH.up(AUTH.java:118)
at org.jgroups.protocols.UNICAST3.handleDataReceived(UNICAST3.java:694)
at org.jgroups.protocols.UNICAST3.up(UNICAST3.java:381)
at org.jgroups.protocols.pbcast.NAKACK2.up(NAKACK2.java:600)
at org.jgroups.protocols.VERIFY_SUSPECT.up(VERIFY_SUSPECT.java:147)
at org.jgroups.protocols.FD.up(FD.java:255)
at org.jgroups.protocols.FD_SOCK.up(FD_SOCK.java:301)
at org.jgroups.protocols.MERGE2.up(MERGE2.java:209)
at org.jgroups.protocols.Discovery.up(Discovery.java:379)
at org.jgroups.protocols.MPING.up(MPING.java:181)
at org.jgroups.protocols.TP.passMessageUp(TP.java:1399)
at org.jgroups.protocols.TP$MyHandler.run(TP.java:1585)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: an exception which occurred:
in object of type org.hibernate.internal.SessionFactoryImpl
in field factory
in object of type org.hibernate.type.TypeFactory$TypeScopeImpl
in field typeScope
in object of type org.hibernate.type.EmbeddedComponentType
in field type
in object of type org.hibernate.cache.spi.CacheKey
以前有人见过这个错误吗?infinispan似乎没有正确序列化嵌入的id类。
我使用的是Hibernate 4.3.5和Infinispan 6.0.2
编辑:
问题是Infinispan正在通过网络发送缓存密钥的序列化版本。该键间接引用启动机器上的sessionfactorympl,但远程机器无法反序列化sessionfactorympl,因此引发此异常。我认为这个问题特定于具有复合主键的实体,因为如果键只是一个长键,则缓存键的类型将不是间接引用SessionFactoryImpl的。
总之,我不确定这是一个Infinispan问题还是一个Hibernate问题。
正如在pull请求上所讨论的,显然只要命名,SessionFactory就可以跨JVM序列化(参见HHH-6822)。为了解决我的问题,我只需要在会话工厂上设置以下Hibernate属性:
hibernate.session_factory_name = MySessionFactory
hibernate.session_factory_name_is_jndi = false
我有一个实体,它的复合主键由两个字段组成,其中一个也是复合外键的一部分。 背景:我有实体<代码>人员 、<代码>区域 和<代码>会话 。 与具有多对多关系,使用称为“和实体。 所以,我有,主键为(,)。本身是的外键。 也有一个字段。我希望(,)是的复合外键。 我的PersonSession代码: } 这看起来不错,它在数据库中创建了所有正确的关系。当我尝试插入个性化会话对象时,问题就出现了——ar
我在读下面的文章: 然而,student实体是用mappedBy注释的,我知道任何用mappedBy注释的实体都是相反的一面。谁能解释一下这个吗? 2-哪个ID是外键?@PrimaryKeyJoinColumn在Address实体中使用,这意味着地址Id是主键和外键吗?在下面的文章中,它们有相同的示例,但它是单向的: http://websystique.com/hibernate/hiberna
我有一个JPA实体的类层次结构,基类是定义了一个ID的MappedSuperclass。我试图在子类中使用复合键,但这似乎不起作用
我在使用复合主键的hibernate实体集时遇到了问题。 我们的应用程序中有一个概念“Target”。目标id应该是其他三个表(实体)主id的组合。目标也有一个int标记。员工应该有一系列目标。SQL如下所示: 这个SQL工作正常,它允许我每个role_id(员工)多个目标,只要应用程序和项目分类不同。 这是目标ID类 这是目标类 这是employee类,我想在其中为每个员工存储一组目标。 通过h
花了3天时间寻找解决方案,最后我来到这里寻求社区智慧。 我有如下的自我引用实体: 我通过手动运行它来确保请求不会返回数据库中的任何内容,但发现如果我将更改为,它将返回数据,因此,块中可能存在错误
我有以下实体: 我第一次使用复合主键,所以我不知道它应该如何工作。问题可能来自定义。第二个参数应该表示ID。但是没有一个主键,而是有两个主键,所以我认为我应该将id类添加到id参数中,但这不起作用。如何使用带有CrudRepository的IdClass键保存具有复合主实体?