-->
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.  [ 4 posts ] 
Author Message
 Post subject: HELP: again "no persistor for" error
PostPosted: Tue Jan 18, 2005 6:25 am 
Newbie

Joined: Mon Jan 17, 2005 9:05 am
Posts: 17
I am doing a very simple test in hibernate 2.1,

I have a table Test1 (
id NUMBER(19, 0),
name VARCHAR2(255),
primary key(id)

)

my Test1 class:
public class Test1 {
private Long id = null;
private String name = null;

public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}


my mapping file Test1.hbm.xml:

[b]Mapping documents:<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="Test1" table="TEST1" >
<id name="id" column="ID" type="long" unsaved-value="null">
<generator class="org.jbpm.persistence.hibernate.ConfigurableIdGenerator" />
</id>
<property name="name" column="NAME" type="string" />

</class>
</hibernate-mapping>
[/b]

my calling class:

[b]public void testHibernate(){
try{
Connection conn = null;

conn = DriverManager.getConnection("jdbc:oracle:oci:@(description=(address=(host=155.161.96.135)(protocol=tcp)(port=1521)) (connect_data=(sid=SCS)))", "scs", "password");


SessionFactory sessionFactory = new Configuration().buildSessionFactory();
Test1 test = new Test1();
test.setName("test");
Session session = sessionFactory.openSession(conn);
session.save(test);
}catch(Exception e){
e.printStackTrace();
}
}[/b]

I have put the Test1.hbm.xml and Test1.java class in the same folder.

When I run the program and try to insert new record into database
i got "no persister for:" error:
0 [main] INFO cfg.Environment - Hibernate 2.1.1
16 [main] INFO cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.username=scs, hibernate.connection.password=password, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect, hibernate.connection.url=jdbc:oracle:oci:@(description=(address=(host=155.161.96.135)(protocol=tcp)(port=1521)) (connect_data=(sid=SCS))) , hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver}
16 [main] INFO cfg.Environment - using CGLIB reflection optimizer
16 [main] INFO cfg.Configuration - processing one-to-many association mappings
16 [main] INFO cfg.Configuration - processing one-to-one association property references
16 [main] INFO cfg.Configuration - processing foreign key constraints
47 [main] INFO dialect.Dialect - Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
110 [main] INFO cfg.SettingsFactory - Use outer join fetching: true
110 [main] INFO connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
110 [main] INFO connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
110 [main] INFO connection.DriverManagerConnectionProvider - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:oci:@(description=(address=(host=155.161.96.135)(protocol=tcp)(port=1521)) (connect_data=(sid=SCS)))
110 [main] INFO connection.DriverManagerConnectionProvider - connection properties: {user=scs, password=password}
125 [main] INFO transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
219 [main] INFO cfg.SettingsFactory - Use scrollable result sets: true
219 [main] INFO cfg.SettingsFactory - JDBC 2 max batch size: 15
219 [main] INFO cfg.SettingsFactory - Query language substitutions: {}
219 [main] INFO cfg.SettingsFactory - cache provider: net.sf.ehcache.hibernate.Provider
219 [main] INFO cfg.Configuration - instantiating and configuring caches
344 [main] INFO impl.SessionFactoryImpl - building session factory
485 [main] INFO impl.SessionFactoryObjectFactory - no JNDI name configured
net.sf.hibernate.MappingException: No persister for: Test1
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2574)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2581)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:725)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
at com.fedex.apacsales.test.persistent.TestHibernate.testHibernate(TestHibernate.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Help me please! i am stuck here for a whole day already :(

[b]Hibernate version:2.1[/b]



[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Top
 Profile  
 
 Post subject: Haev you got a hibernate.cfg.xml ??
PostPosted: Tue Jan 18, 2005 9:54 am 
Newbie

Joined: Wed Jan 12, 2005 1:11 pm
Posts: 4
Location: London
it should look a bit like this :-

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <!-- a SessionFactory instance listed as /jndi/name -->
    <session-factory name="SessionFactory">

        <!-- START WEBSERVER_CONFIG -->
        <property name="hibernate.connection.datasource">jdbc/Datasource</property>
        <property name="hibernate.connection.pool_size">10</property>
        <!-- END WEBSERVER_CONFIG -->

        <!-- START TEST_CONFIG -->
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">%DB%</property>
        <property name="hibernate.connection.username">%USER%</property>
        <property name="hibernate.connection.password">%PASSWORD%</property>
        <!-- END TEST_CONFIG -->

        <property name="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.session_factory_name"></property>

        <!-- mapping files -->

        <!-- Queries -->
        <mapping resource="/path/of/package/Test1.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


This needs to be in the root of your classpath, and list all the maping files. If this isn't the problem, then can you post your hibernate.cfg.xml please, and I'll have another look.

Chris


Top
 Profile  
 
 Post subject: Missed a bit ...
PostPosted: Tue Jan 18, 2005 9:59 am 
Newbie

Joined: Wed Jan 12, 2005 1:11 pm
Posts: 4
Location: London
you also need to change your code slightly ...

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();


Top
 Profile  
 
 Post subject: it solve
PostPosted: Wed Jan 19, 2005 2:26 am 
Newbie

Joined: Mon Jan 17, 2005 9:05 am
Posts: 17
Hi,

Thanks for you guys' help. It solve. I forgot to add the following codes in my calling class

new Configuration().addClass(XXXX.class)
new Configuration().setProperties(XXXXX.properties); //properties file

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.