[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Session.Save work fine, Session.update Unknown entity ?!?!?!
gaquino
do-not-reply at jboss.com
Tue Aug 29 17:44:21 EDT 2006
Hi ,
I have work using Hibernate 3 with MBean in Jboss 4.0.4. and ans increrible thinks happend.. in same code, same mapping.. i use session.save to create a registry this work fine, but if i use session.update or session.saveOrUpdate to update one registry im receive the error:
- nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=BCO-SIST-002/169, BranchQual=, localId=169] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.MappingException: Unknown entity: br.com.bvsistemas.servicoteste.data.VUsuario))
Some one can help me about this ???
Thx
hibernate-service.xml
<server>
| <mbean code="org.jboss.hibernate.jmx.Hibernate"
| name="jboss.adminguide:name=BVServicoTesteFactory">
| <attribute name="DatasourceName">java:MysqlTeste</attribute>
| <attribute name="Dialect">
| org.hibernate.dialect.MySQLDialect
| </attribute>
| <attribute name="SessionFactoryName">
| java:/hibernate/BVServicoTesteFactory
| </attribute>
| <attribute name="CacheProviderClass">
| org.hibernate.cache.HashtableCacheProvider
| </attribute>
| <attribute name="ShowSqlEnabled">true</attribute>
| <attribute name="DefaultSchema">dbteste</attribute>
| <attribute name="MaxFetchDepth">8</attribute>
| <attribute name="JdbcBatchSize">1000</attribute>
| <attribute name="JdbcFetchSize">5000</attribute>
| <attribute name="ReflectionOptimizationEnabled">true</attribute>
| <attribute name="QueryCacheEnabled">true</attribute>
| <attribute name="SessionFactoryInterceptor">br.com.bvsistemas.framework.interceptor.AuditHibernateInterceptor</attribute>
| </mbean>
| </server>
|
VUsuario.hbm.xml
<?xml version="1.0"?>
| <!DOCTYPE hibernate-mapping PUBLIC
| "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
| "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
|
| <hibernate-mapping>
| <!--
| Created by the Middlegen Hibernate plugin 2.2
|
| http://boss.bekk.no/boss/middlegen/
| http://www.hibernate.org/
| -->
|
| <class
| name="br.com.bvsistemas.servicoteste.data.VUsuario"
| table="tbusuario"
| lazy="false"
| schema="dbteste"
| >
|
| <id
| name="cdUsuario"
| type="java.lang.Integer"
| column="CdUsuario"
| >
|
| <generator class="increment" />
| </id>
|
| <property
| name="nmUsuario"
| type="java.lang.String"
| column="NmUsuario"
| length="100"
| />
|
| <!-- Associations -->
|
|
| </class>
| </hibernate-mapping>
VUsuario.java
public class VUsuario extends BaseVUsuario implements IVUsuario,IAuditar{
|
|
| /**
| *
| */
| private static final long serialVersionUID = 8354978809242555880L;
|
|
| /*[CONSTRUCTOR MARKER BEGIN]*/
| public VUsuario () {
| super();
| }
|
| /**
| * Constructor for primary key
| */
| public VUsuario (java.lang.Integer cdUsuario) {
| super(cdUsuario);
| }
|
| /*[CONSTRUCTOR MARKER END]*/
|
| /* (non-Javadoc)
| * @see br.com.bvsistemas.framework.auditoria.IAuditar#getId()
| */
| public String getId() {
| return super.getCdUsuario().toString();
| }
| }
BaseVUsuario.java
| public abstract class BaseVUsuario implements Comparable, Serializable {
|
| public static String REF = "VUsuario";
| public static String PROP_NM_USUARIO = "nmUsuario";
| public static String PROP_CD_USUARIO = "cdUsuario";
|
|
| // constructors
| public BaseVUsuario () {
| initialize();
| }
|
| /**
| * Constructor for primary key
| */
| public BaseVUsuario (java.lang.Integer cdUsuario) {
| this.setCdUsuario(cdUsuario);
| initialize();
| }
|
| protected void initialize () {}
|
|
|
| private int hashCode = Integer.MIN_VALUE;
|
| // primary key
| private java.lang.Integer cdUsuario;
|
| // fields
| private java.lang.String nmUsuario;
|
|
|
| /**
| * Return the unique identifier of this class
| * @hibernate.id
| * generator-class="increment"
| * column="CdUsuario"
| */
| public java.lang.Integer getCdUsuario () {
| return cdUsuario;
| }
|
| /**
| * Set the unique identifier of this class
| * @param cdUsuario the new ID
| */
| public void setCdUsuario (java.lang.Integer cdUsuario) {
| this.cdUsuario = cdUsuario;
| this.hashCode = Integer.MIN_VALUE;
| }
|
|
|
|
| /**
| * Return the value associated with the column: NmUsuario
| */
| public java.lang.String getNmUsuario () {
| return nmUsuario;
| }
|
| /**
| * Set the value related to the column: NmUsuario
| * @param nmUsuario the NmUsuario value
| */
| public void setNmUsuario (java.lang.String nmUsuario) {
| this.nmUsuario = nmUsuario;
| }
|
|
|
|
|
| public boolean equals (Object obj) {
| if (null == obj) return false;
| if (!(obj instanceof br.com.bvsistemas.servicoteste.data.VUsuario)) return false;
| else {
| br.com.bvsistemas.servicoteste.data.VUsuario vUsuario = (br.com.bvsistemas.servicoteste.data.VUsuario) obj;
| if (null == this.getCdUsuario() || null == vUsuario.getCdUsuario()) return false;
| else return (this.getCdUsuario().equals(vUsuario.getCdUsuario()));
| }
| }
|
| public int hashCode () {
| if (Integer.MIN_VALUE == this.hashCode) {
| if (null == this.getCdUsuario()) return super.hashCode();
| else {
| String hashStr = this.getClass().getName() + ":" + this.getCdUsuario().hashCode();
| this.hashCode = hashStr.hashCode();
| }
| }
| return this.hashCode;
| }
|
| public int compareTo (Object obj) {
| if (obj.hashCode() > hashCode()) return 1;
| else if (obj.hashCode() < hashCode()) return -1;
| else return 0;
| }
|
| public String toString () {
| return super.toString();
| }
|
|
| }
The Code test Save/Update
| // The entity populate
| VUsuario usuarioDTO = new VUsuario();
| usuarioDTO.setCdUsuario(3389);
| usuarioDTO.setNmUsuario("Nina");
|
| // Get the session
| final InitialContext ctx = new InitialContext();
| final SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/BVServicoTesteFactory");
| Session sessao = factory.openSession();
|
| sessao.save(usuarioDTO)
|
| // Change the value to update other registry
| usuarioDTO.setCdUsuario(3380);
| usuarioDTO.setNmUsuario("Gustavo");
| sessao.update(usuarioDTO);
|
| sessao.flush();
| sessao.close();
|
This is the error:
org.jboss.tm.JBossTransactionRolledbackLocalException: - nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=BCO-SIST-002/169, BranchQual=, localId=169] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.MappingException: Unknown entity: br.com.bvsistemas.servicoteste.data.VUsuario))
at org.jboss.ejb.plugins.TxInterceptorCMT.throwJBossException(TxInterceptorCMT.java:565)
at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:506)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:411)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)
at org.jboss.ejb.Container.invoke(Container.java:954)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:430)
at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:103)
at $Proxy66.atualizarUsuario(Unknown Source)
... 48 more
Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=BCO-SIST-002/169, BranchQual=, localId=169] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.MappingException: Unknown entity: br.com.bvsistemas.servicoteste.data.VUsuario)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:501)
... 58 more
Caused by: org.hibernate.MappingException: Unknown entity: br.com.bvsistemas.servicoteste.data.VUsuario
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:547)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:65)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:871)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:801)
at br.com.bvsistemas.framework.interceptor.AuditHibernateInterceptor.onFlushDirty(AuditHibernateInterceptor.java:108)
at org.hibernate.event.def.DefaultFlushEntityEventListener.invokeInterceptor(DefaultFlushEntityEventListener.java:325)
at org.hibernate.event.def.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:301)
at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:241)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:59)
at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
... 59 more
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968235#3968235
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3968235
More information about the jboss-user
mailing list