Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class lazy="false"
optimistic-lock="version"
dynamic-update="true"
name="de.bitmanager.fairtracks.xmlimport.vo.Track" table="track" node="track">
<id name="id" type="int" unsaved-value="-1" node="@id">
<column name="id" sql-type="int" not-null="true"/>
<generator class="native">
<param name="sequence">sq_track</param>
</generator>
</id>
<version name="version" unsaved-value="negative"/>
<property name="name" node="name" />
<property name="url" node="url"/>
<property name="skipUrl" node="skipUrl"/>
<property name="rating" node="rating"/>
<property name="creationDate" node="creationDate"/>
<property name="albumPosition" node="albumPosition"/>
<property name="referenceTrack" node="referenceTrack"/>
<property name="tracklen" node="tracklen"/>
<property name="isrc" node="isrc"/>
<property name="trackArtist" node="trackArtist"/>
<property name="trackTexter" node="trackTexter"/>
<property name="trackComposer" node="trackComposer"/>
<property name="trackProducer" node="trackProducer"/>
<property name="setNumber" node="setNumber"/>
<property name="publishingInfo" node="publishingInfo"/>
<property name="updateTime" column="update_time" not-null="true"/>
<property name="updateUser" column="update_user" not-null="true"/>
<property name="tenantId" column="tenant_id" not-null="true"/>
<filter
name="tenantFilter"
condition=":tenantId = tenant_id" />
</class>
<filter-def name="tenantFilter">
<filter-param name="tenantId" type="integer"/>
</filter-def>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
SAXReader reader = new SAXReader();
try {
Document doc = reader.read(new File(path));
Element root = doc.getRootElement();
Element track = root.element("track");
Session s;
try {
s = this.getBase().openSession();
Transaction t = s.beginTransaction();
s.persist( track );
t.commit();
s.close();
} catch (ORException e) {
e.printStackTrace();
}
} catch (DocumentException e) {
e.printStackTrace();
}
Full stack trace of any exception that occurs:
org.hibernate.MappingException: Unknown entity: tracks
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:610)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1246)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:459)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:70)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:590)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:568)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:572)
at de.bitmanager.fairtracks.xmlimport.service.impl.TrackImportServiceImpl.readXML(TrackImportServiceImpl.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.java:584)
at org.jboss.ejb.plugins.StatefulHASessionSynchronisationInterceptor.invoke(StatefulHASessionSynchronisationInterceptor.java:93)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:315)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.CleanShutdownInterceptor.invoke(CleanShutdownInterceptor.java:264)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:873)
at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
at org.jboss.invocation.jrmp.server.JRMPInvokerHA.invoke(JRMPInvokerHA.java:163)
at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Name and version of the database you are using:
Oracle 10g
XML-Document:
<?xml version="1.0" encoding="UTF-8"?>
<tracks>
<track id="1412">
<version>3</version>
<name>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (Out Goes The Light)</name>
<url>The_Animals_feat_Eric_Burdon_-_Boom_Boom_(Out_Goes_The_Light)12.mp3</url>
<skipUrl>skip_The_Animals_feat_Eric_Burdon_-_Boom_Boom_(Out_Goes_The_Light)12.mp3</skipUrl>
<creationDate>2006-03-28 13:33:42</creationDate>
<albumPosition>12</albumPosition>
<referenceTrack>false</referenceTrack>
<tracklen>196</tracklen>
<isrc>DE-A37-05-04301</isrc>
<trackArtist>The Animals feat. Eric Burdon</trackArtist>
<trackTexter>John Lee Hooker</trackTexter>
<trackComposer>John Lee Hooker</trackComposer>
<setNumber>1</setNumber>
<publishingInfo>Conrad Music Inc., ARC Music Corp., Coachman Edition</publishingInfo>
<updateTime>2006-03-30 15:29:59</updateTime>
<updateUser>bierg</updateUser>
<tenantId>1</tenantId>
</track>
</tracks>
Hallo,
ich versuche einen XML Import mit Hibernate vorzunehmen und bekomme oben erwähnte Fehlermeldung. Diese Meldung bekomme ich auch, wenn ich nicht das Root Element "tracks" sondern eines der Elemente "track" verwende. Was könnte falsch sein? Muss ich das root angeben oder eines der Elemente? Werden dann automatisch alle folgenden durchgegangen?
Danke für die Hilfe,
Jan