-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem "Unknown entity" when trying to save
PostPosted: Mon Mar 13, 2006 6:36 am 
Newbie

Joined: Mon Mar 13, 2006 6:25 am
Posts: 2
Hibernate version: 3.1

Mapping documents:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@oracle.stud.aitel.hist.no:1521:oracle</property>
        <property name="hibernate.connection.username">vinbutikken</property>
        <property name="hibernate.connection.password">prosjektv06</property>
        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <property name="show_sql">true</property>
        <property name="hibernate.transaction.factory_class">
             org.hibernate.transaction.JDBCTransactionFactory
        </property>
        <property name="hibernate.cache.provider_class">
             org.hibernate.cache.HashtableCacheProvider
        </property>
        <property name="hibernate.hbm2ddl.auto">update</property>
       
        <property name="showsql">true</property>
        <property name="hbm2ddl.auto">create</property>
        <mapping resource="vinbutikk/hbm/Vin.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Bestilling.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/BestillingStatus.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/BestiltVare.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Bruker.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/BrukerKarakter.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Land.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Leverandor.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Postnummer.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Region.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/UkensVin.hbm.xml"/>
        <mapping resource="vinbutikk/hbm/Vintype.hbm.xml"/>
    </session-factory>

</hibernate-configuration>

Example entity document:
Code:
<?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>

    <class name="vinbutikk.PostnummerBean" table="HIB_POSTNR">
        <id name="id" column="id" type="long">
                <generator class="increment"/>
        </id>
        <property name="postnummer" type="string"/>
        <property name="poststed" type="string"/>
    </class>

</hibernate-mapping>


Main class:
Code:
package vinbutikk;
/*
* Main.java
*
* Created on February 20, 2006, 11:18 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

import vinbutikk.util.HibernateUtil;
import javax.transaction.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
/**
*
* @author christian
*/
public class Main {
   
    /** Creates a new instance of Main */
    public Main() {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
       
        //SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session s = HibernateUtil.getSession();
        //Session s = sf.getCurrentSession();
        //System.err.print(s.toString());
        s.beginTransaction();
        PostnummerBean pn = new PostnummerBean("7075","Tiller");
        //Transaction tx = s.beginTransaction();
        s.save(pn);
        s.getTransaction().commit();
        HibernateUtil.getSessionFactory().close();
       
       
       
       
    }
   
}


My HibernateUtil.java:

Code:
package vinbutikk.util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
   
    public static Session getSession() {
        return sessionFactory.openSession();
    }

}

Full stack trace of any exception that occurs:
(Cut away lots of "INFO" lines that contained no errors)
Code:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: vinbutikk.PostnummerBean
        at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:513)
        at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1321)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:89)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
        at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
        at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
        at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:559)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:543)
        at vinbutikk.Main.main(Main.java:38)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


Name and version of the database you are using:
Oracle 9

Nothing gets input in to the database. It just stops execution at "s.save(pn)".
Have I missed something about mappings?

EDIT: The PostnummerBean.java file is generated by hbm2java and is correctly placed in vinbutikken/PostnummerBean.java
And yes, I have compiled it.
Does it matter that I'm using Netbeans (5)?

Regz,
Christian W.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 12:53 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 9:52 am
Posts: 52
Location: Zurich
Hello,
Should it say:
<mapping resource="vinbutikk/hbm/PostnummerBean.hbm.xml">
in you hibernate.cfg.hbm file?

Hope this helps!
Urs


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 2:53 pm 
Newbie

Joined: Mon Mar 13, 2006 6:25 am
Posts: 2
Thanks, but no. The hbm files does not have the "Bean" ending. Or maybe that is exactly the problem.

I'll try renaming all the hbm's and we'll se what happens.

-Christian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.