-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem beim Insert
PostPosted: Wed Aug 16, 2006 5:47 am 
Newbie

Joined: Tue Jun 06, 2006 6:41 am
Posts: 3
Hallo zusammen,

bin ein Neuling in Hibernate und bräuchte eure Hilfe!
Ich versuche Contaktdaten in die Tabelle Contact hizufügen, krige aber eine Null zurück, warum auch immer, hat jemand eine Idee?
Danke im voraus

der code sieht wie folgt aus:

*********************************************************
....
private static SessionFactory sessionFactory;

Session session = null;
Transaction transaction = null;
try {
session = sessionFactory.openSession();
sessionFactory = new
Configuration().configure().buildSessionFactory()
transaction = session.beginTransaction();

Contact contact = new Contact();
contact.setId(1);
contact.setFirstName("firstname");
contact.setLastName("lasName");
contact.setEmail("test@email.com");
session.save(contact);
transaction.commit();
System.out.println("done");
.....
*********************************************************
Mapping-file:

class name="package.Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="increment"/>
</id>

<property name="firstName" column="FIRSTNAME" type="string" not-null="true"/>
<property name="lastName" column="LASTNAME" type="string"/>
</property>
<property name="email" column="EMAIL" type="string">
*********************************************************


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:26 am 
Beginner
Beginner

Joined: Thu Jul 20, 2006 12:08 pm
Posts: 21
Location: Germany
bitte mal die hibernate.cfg.xml datei und das log posten.

_________________
marlon
---
don't hesitate to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 9:06 am 
Newbie

Joined: Tue Jun 06, 2006 6:41 am
Posts: 3
marlon wrote:
bitte mal die hibernate.cfg.xml datei und das log posten.


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

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:C:/Test/Hibernate/hSqlDbData/myDB</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
************************************************************
Log-File enthält einfach nur paar so "komische" nicht lesbare Zeichen

Danke

bzgl. die Bewertung keine Sorge würde ich gerne machen


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 9:12 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Wo bekommst Du null zurück?

Log File wäre sehr interessant (level: debug)

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 9:17 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Ich glaub ich habs gefunden:

Code:
private static SessionFactory sessionFactory;

Session session = null;
Transaction transaction = null;
try {
session = sessionFactory.openSession();


Kann es sein, dass Du die Variable sessionFactory nicht initialisierst und deshalb beim Aufruf von sessionFactory.openSession() eine NullPointerException bekommst?

Da Du die XML Konfiguration verwendest sollte folgender code lauffähig sein:


Code:
private static SessionFactory sessionFactory;

Session session = null;
Transaction transaction = null;
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();


Neu hinzugekommen ist das SessionFactory Ramp Up mit
sessionFactory = new Configuration().configure().buildSessionFactory();

Das ganze ist in der Doku hier nachzulesen:
http://www.hibernate.org/hib_docs/v3/re ... -xmlconfig

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 9:25 am 
Newbie

Joined: Tue Jun 06, 2006 6:41 am
Posts: 3
MikePloed wrote:
Ich glaub ich habs gefunden:

Code:
private static SessionFactory sessionFactory;

Session session = null;
Transaction transaction = null;
try {
session = sessionFactory.openSession();


Kann es sein, dass Du die Variable sessionFactory nicht initialisierst und deshalb beim Aufruf von sessionFactory.openSession() eine NullPointerException bekommst?

Da Du die XML Konfiguration verwendest sollte folgender code lauffähig sein:


Code:
private static SessionFactory sessionFactory;

Session session = null;
Transaction transaction = null;
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();


Neu hinzugekommen ist das SessionFactory Ramp Up mit
sessionFactory = new Configuration().configure().buildSessionFactory();

Das ganze ist in der Doku hier nachzulesen:
http://www.hibernate.org/hib_docs/v3/re ... -xmlconfig


richtig :)
danke, danke


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.