[Persistence, JBoss/CMP, Hibernate, Database] - JPA problem with insert
by tovar
Hi. I have problem with inserting in database.
I don't know how to insert object and disable an attempt of inserting in related tables.
example:
@Entity
@Table(name = "MAIN_TABLE", schema = "SCH")
@Inheritance(strategy=InheritanceType.JOINED)
public class MainClass extends MainDataObject {
@Id
public Integer id;
@Column(name = "session", nullable = false)
@ManyToOne(optional = false, cascade = CascadeType.PERSIST)
@JoinColumn(name="session",referencedColumnName="id")
public ProblematicSession session;
@Column(name = "destination_member_state", nullable = false, length = 2)
@ManyToOne(optional = false, cascade = CascadeType.PERSIST)
@JoinColumn(name="destination_member_state",referencedColumnName="country_code")
public Country destinationMemberState;
---------------------------------------------------
@Entity
@Table(name = "PROBBLEMATICTABLE", schema = "SCH")
public class ProblematicSession extends MainDataObject {
@Id
@Column(insertable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer id;
Database create ID, so I put insertable = false and strategy=GenerationType.IDENTITY.
When I insert into MAIN_TABLE, how to disable an attempt of inserting in related table (PROBBLEMATICTABLE).
if I set for example ProblematicSession.id = 1 error is:
This existing value was either provided via an initializer or by calling the setter method. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.
If I set ProblematicSession.id = null, also try to insert into PROBBLEMATICTABLE. A do not want that!!!
Also I have table where database do not insert primary key, and there is no problem (Country).
@Id
@Column(name = "country_code", nullable = false, length = 2)
public String countryCode;
public String getCountryCode() {
return countryCode;
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4157485#4157485
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4157485
17 years, 11 months
[JBoss Cache: Core Edition] - Re: Lock timeout exceptions
by ajassal
Brian,
Thanks. Here you go:
INFO 2008-06-11 18:50:34,071 UpHandler (GMS) U- org.jboss.cache.interceptors.TxInterceptor - There was a problem handling this request
org.jboss.cache.lock.TimeoutException: failure acquiring lock: fqn=/user/id, caller=Thread[UpHandler (GMS),5,JGroups threads], lock= (activeReaders=0, activeWriter=null, waitingReaders=0, waitingWriters=0, waitingUpgrader=0)
at org.jboss.cache.Node.acquire(Node.java:500)
at org.jboss.cache.interceptors.PessimisticLockInterceptor.acquireNodeLock(PessimisticLockInterceptor.java:342)
at org.jboss.cache.interceptors.PessimisticLockInterceptor.lock(PessimisticLockInterceptor.java:287)
at org.jboss.cache.interceptors.PessimisticLockInterceptor.invoke(PessimisticLockInterceptor.java:178)
at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
at org.jboss.cache.interceptors.UnlockInterceptor.invoke(UnlockInterceptor.java:32)
at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
at org.jboss.cache.interceptors.InvalidationInterceptor.invoke(InvalidationInterceptor.java:60)
at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
at org.jboss.cache.interceptors.TxInterceptor.handleNonTxMethod(TxInterceptor.java:364)
at org.jboss.cache.interceptors.TxInterceptor.invoke(TxInterceptor.java:160)
at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
at org.jboss.cache.interceptors.CacheMgmtInterceptor.invoke(CacheMgmtInterceptor.java:179)
at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5710)
at org.jboss.cache.TreeCache._replicate(TreeCache.java:5056)
at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jgroups.blocks.MethodCall.invoke(MethodCall.java:330)
at org.jgroups.blocks.RpcDispatcher.handle(RpcDispatcher.java:281)
at org.jgroups.blocks.RequestCorrelator.handleRequest(RequestCorrelator.java:650)
at org.jgroups.blocks.RequestCorrelator.receiveMessage(RequestCorrelator.java:535)
at org.jgroups.blocks.RequestCorrelator.receive(RequestCorrelator.java:358)
at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.up(MessageDispatcher.java:775)
at org.jgroups.JChannel.up(JChannel.java:1091)
at org.jgroups.stack.ProtocolStack.up(ProtocolStack.java:377)
at org.jgroups.stack.ProtocolStack.receiveUpEvent(ProtocolStack.java:393)
at org.jgroups.stack.Protocol.passUp(Protocol.java:538)
at org.jgroups.protocols.pbcast.STATE_TRANSFER.up(STATE_TRANSFER.java:158)
at org.jgroups.stack.Protocol.receiveUpEvent(Protocol.java:488)
at org.jgroups.stack.Protocol.passUp(Protocol.java:538)
at org.jgroups.protocols.pbcast.GMS.up(GMS.java:771)
at org.jgroups.stack.UpHandler.run(Protocol.java:60)
Caused by: org.jboss.cache.lock.TimeoutException: read lock for /user/id could not be acquired by Thread[UpHandler (GMS),5,JGroups threads] after 0 ms. Locks: Read lock owners: []
Write lock owner: null
, lock info: (activeReaders=0, activeWriter=null, waitingReaders=0, waitingWriters=0, waitingUpgrader=0)
at org.jboss.cache.lock.IdentityLock.acquireReadLock(IdentityLock.java:261)
at org.jboss.cache.Node.acquireReadLock(Node.java:512)
at org.jboss.cache.Node.acquire(Node.java:474)
... 32 more
WARN 2008-06-11 18:50:34,072 UpHandler (GMS) U- org.jboss.cache.TreeCache - replication failure with method_call _evict; id:8(/user/id/655382) exception: org.jboss.cache.lock.TimeoutException: failure acquiring lock: fqn=/user/id, caller=Thread[UpHandler (GMS),5,JGroups threads], lock= (activeReaders=0, activeWriter=null, waitingReaders=0, waitingWriters=0, waitingUpgrader=0)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4157482#4157482
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4157482
17 years, 11 months