-->
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: hibernate doesn't stores data in DB
PostPosted: Wed Nov 16, 2011 7:43 am 
Newbie

Joined: Wed Nov 16, 2011 7:30 am
Posts: 3
I did the following program:

Quote:
class Test{

public static void main(String[] args){

CD cd = new CD("Piero", "Morgana", new Date(), 12.99);

try{

Configuration cfg = new Configuration().addClass(CD.class);
SessionFactory sessionFactory = cfg.buildSessionFactory();

Session session = sessionFactory.openSession();
session.save(cd);
session.flush();
session.close();

} catch (Exception e){}

}

}


the error is this:

Quote:
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environm
ent).
log4j:WARN Please initialize the log4j system properly.


I found a log4j.properties in the hibernate code and I put in my source code. the result is:

Quote:
C:\Documents and Settings\trattino\myapp>java Test
23:15:21,032 INFO Environment:432 - Hibernate 2.1 final
23:15:21,032 INFO Environment:466 - loaded properties from resource hibernate.p
roperties: {hibernate.connection.username=root, hibernate.connection.password=we
r, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hiber
nate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.connection.url=jdb
c:mysql://localhost/products, hibernate.connection.driver_class=com.mysql.jdbc.D
river}
23:15:21,048 INFO Environment:481 - using CGLIB reflection optimizer
23:15:21,048 INFO Configuration:305 - Mapping resource: CD.hbm.xml
23:15:21,376 INFO Binder:220 - Mapping class: CD -> cd
23:15:21,438 INFO Configuration:571 - processing one-to-many association mappin
gs
23:15:21,438 INFO Configuration:580 - processing one-to-one association propert
y references
23:15:21,438 INFO Configuration:605 - processing foreign key constraints
23:15:21,438 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDia
lect
23:15:21,454 INFO SettingsFactory:62 - Use outer join fetching: true
23:15:21,454 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in
connection pool (not for production use!)
23:15:21,454 INFO DriverManagerConnectionProvider:42 - Hibernate connection poo
l size: 20
23:15:21,454 INFO DriverManagerConnectionProvider:71 - using driver: com.mysql.
jdbc.Driver at URL: jdbc:mysql://localhost/products
23:15:21,454 INFO DriverManagerConnectionProvider:72 - connection properties: {
user=root, password=wer}
23:15:21,454 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLoo
kup configured (in JTA environment, use of process level read-write cache is not
recommended)
23:15:21,657 INFO SettingsFactory:89 - Use scrollable result sets: true
23:15:21,657 INFO SettingsFactory:90 - JDBC 2 max batch size: 15
23:15:21,657 INFO SettingsFactory:96 - echoing all SQL to stdout
23:15:21,657 INFO SettingsFactory:99 - Query language substitutions: {}
23:15:21,657 INFO SettingsFactory:110 - cache provider: net.sf.ehcache.hibernat
e.Provider
23:15:21,657 INFO Configuration:1044 - instantiating and configuring caches
23:15:21,735 INFO SessionFactoryImpl:118 - building session factory
23:15:21,938 INFO SessionFactoryObjectFactory:82 - no JNDI name configured


What does it mean? the record that i would put hasn't been stored...


Top
 Profile  
 
 Post subject: Re: hibernate doesn't stores data in DB
PostPosted: Sat Nov 19, 2011 10:22 am 
Newbie

Joined: Wed Nov 16, 2011 7:30 am
Posts: 3
Pls suggest.


Top
 Profile  
 
 Post subject: Re: hibernate doesn't stores data in DB
PostPosted: Thu Nov 24, 2011 8:50 pm 
Newbie

Joined: Wed Nov 16, 2011 7:30 am
Posts: 3
this is a java standalone application...

INFO SessionFactoryObjectFactory:82 - no JNDI name configured

how and where should I set the jndi name?


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

<hibernate-configuration>
  <session-factory name="java:comp/env/hibernate/SessionFactory">
    <property name = "connection.datasource">jdbc/products </property>
   <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="connection.url">jdbc:mysql://localhost/products</property>
   <property name="connection.username"></property>
   <property name="connection.password"></property>
   <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>



hibernate.properties
Code:
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/products
hibernate.connection.username root
hibernate.connection.password wer

hibernate.show_sql true



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

<hibernate-mapping>
   <class name="CD"
      table="cd">
      <id name="Id"
            type="string"
            unsaved-value="null">
         <column name="ID"
              sql-type="text"
              not-null="true"/>
         <generator class="hilo"/>
      </id>

      <property name="title"/>
      <property name="artist"/>
      <property name="purchasedate" type="date"/>
      <property name="cost" type="double"/>
   </class>
</hibernate-mapping>




CD.java
Code:
import java.io.*;
import java.util.*;

  public class CD {
    String id;
    String title;
    String artist;
    Date   purchaseDate;
    double cost;

    public CD() {
    }

    public CD(String title, String artist, Date purchaseDate, double cost) {
      this.title = title;
      this.artist = artist;
      this.purchaseDate = purchaseDate;
      this.cost = cost;
    }

    public void setId(String id) {
      this.id = id;
    }

    public String getId(){
      return id;
    }

    public void setTitle(String title) {
      this.title = title;
    }

    public String getTitle() {
      return title;
    }

    public void setArtist(String artist) {
       this.artist = artist;
    }

    public String getArtist() {
      return artist;
    }

    public void setPurchasedate(Date purchaseDate) {
      this.purchaseDate = purchaseDate;
    }

    public Date getPurchasedate() {
      return purchaseDate;
    }

    public void setCost(double cost) {
      this.cost = cost;
    }

    public double getCost() {
      return cost;
    }
  }


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.