-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate Problem .?
PostPosted: Thu Oct 27, 2011 10:16 pm 
Newbie

Joined: Thu Oct 27, 2011 10:12 pm
Posts: 1
hello java Experts, when i develop basic Java Hibernate Application
with :

1)Java presisted Class (ContactInfo.java)

the class Contact Info:
Code:
package demo;

public class ContactInfo {
   
    private long id;
    private String fName;
    private String lName;
    private PhoneNumber phone;

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

    public long getId() {
        return id;
    }

    public void setFName(String fName) {
        this.fName = fName;
    }

    public String getFName() {
        return fName;
    }

    public void setLName(String lName) {
        this.lName = lName;
    }

    public String getLName() {
        return lName;
    }

    public void setPhone(PhoneNumber phone) {
        this.phone = phone;
    }

    public PhoneNumber getPhone() {
        return phone;
    }
}


The PhoneNumber Class:
Code:
package demo;

public class PhoneNumber {
   
    private String countryCode;
    private String areaCode;
    private String number;

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getNumber() {
        return number;
    }
}




2)hibernate.cfg.xml
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>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/Shahpoup</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">10</property>
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <!-- Enable Hibernate's current session context -->
        <property name="current_session_context_class">thread</property>
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <!-- Drop and re-create the database schema on startup -->
        <!--
        <property name="hbm2ddl.auto">create</property>

        <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
        <mapping resource="org/hibernate/tutorial/domain/Person.hbm.xml"/>
-->
    </session-factory>
</hibernate-configuration>


3)ContactInfo.hbm.xml

Code:
<?xml version="1.0" encoding="windows-1256" ?>
<hibernate-mapping>
    <class name="demo.ContactInfo" table="CONTACTS">
        <id name="”id”" column="”PK”">
            <generator class="”increment”"/>
        </id>
        <property name="fName" column="FNAME" length="40"/>
        <property name="lName" column="LNAME" length="40"/>
        <component name="phone">
            <property name="countryCode" column="CCODE" length="3"/>
            <property name="areaCode" column="ACODE" length="3"/>
            <property name="number" column="NUMBER" length="15"/>
        </component>
    </class>
</hibernate-mapping>




the result:
the log file :
Code:

03:47:46,893  INFO Environment:543 - Hibernate 3.3.0.SP1
03:47:46,904  INFO Environment:576 - hibernate.properties not found
03:47:46,912  INFO Environment:709 - Bytecode provider name : javassist
03:47:46,920  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
03:47:47,016  INFO Configuration:1460 - configuring from resource: hibernate.cfg.xml
03:47:47,017  INFO Configuration:1437 - Configuration resource: hibernate.cfg.xml
03:47:47,133 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
03:47:47,133 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
03:47:47,139 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
03:47:47,207 DEBUG Configuration:1421 - connection.driver_class=com.mysql.jdbc.Driver
03:47:47,207 DEBUG Configuration:1421 - connection.url=jdbc:mysql://localhost:3306/Shahpoup
03:47:47,208 DEBUG Configuration:1421 - connection.username=root
03:47:47,208 DEBUG Configuration:1421 - connection.password=root
03:47:47,209 DEBUG Configuration:1421 - connection.pool_size=2
03:47:47,209 DEBUG Configuration:1421 - dialect=org.hibernate.dialect.MySQLDialect
03:47:47,210 DEBUG Configuration:1421 - current_session_context_class=thread
03:47:47,210 DEBUG Configuration:1421 - cache.provider_class=org.hibernate.cache.NoCacheProvider
03:47:47,210 DEBUG Configuration:1421 - show_sql=true
03:47:47,211  INFO Configuration:1575 - Configured SessionFactory: null
03:47:47,212 DEBUG Configuration:1576 - properties: {java.vendor=Sun Microsystems Inc., show_sql=true, sun.java.launcher=SUN_STANDARD, hibernate.connection.url=jdbc:mysql://localhost:3306/Shahpoup, sun.management.compiler=HotSpot Client Compiler, os.name=Windows 7,
03:47:47,250  INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
03:47:47,333 DEBUG Configuration:1153 - processing extends queue
03:47:47,334 DEBUG Configuration:1157 - processing collection mappings
03:47:47,334 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
03:47:47,335 DEBUG Configuration:1176 - processing association property references
03:47:47,335 DEBUG Configuration:1198 - processing foreign key constraints
03:47:47,339 DEBUG Configuration:1153 - processing extends queue
03:47:47,339 DEBUG Configuration:1157 - processing collection mappings
03:47:47,340 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
03:47:47,340 DEBUG Configuration:1176 - processing association property references
03:47:47,341 DEBUG Configuration:1198 - processing foreign key constraints
03:47:47,347  INFO SchemaExport:226 - Running hbm2ddl schema export
03:47:47,349 DEBUG SchemaExport:242 - import file not found: /import.sql
03:47:47,349  INFO SchemaExport:251 - exporting generated schema to database
03:47:47,360  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
03:47:47,360  INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 2
03:47:47,361  INFO DriverManagerConnectionProvider:68 - autocommit mode: false
03:47:47,375  INFO DriverManagerConnectionProvider:103 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/Shahpoup
03:47:47,376  INFO DriverManagerConnectionProvider:106 - connection properties: {user=root, password=root}
03:47:47,377 TRACE DriverManagerConnectionProvider:116 - total checked-out connections: 0
03:47:47,377 DEBUG DriverManagerConnectionProvider:132 - opening new JDBC connection
03:47:48,002 DEBUG DriverManagerConnectionProvider:138 - created connection to: jdbc:mysql://localhost:3306/Shahpoup, Isolation Level: 4
03:47:48,004  INFO SchemaExport:268 - schema export complete
03:47:48,006 TRACE DriverManagerConnectionProvider:152 - returning connection to pool, pool size: 1
03:47:48,006  INFO DriverManagerConnectionProvider:170 - cleaning up connection pool: jdbc:mysql://localhost:3306/Shahpoup
Process exited with exit code 0.

there is no error but there is no output change the Schema .
i think from ( hibernate.properties not found).

i put the configuration files in demo package with classes and try them in resources but
there is no sql code generated so, there is no changes applied to database schema
what is the solution of this problem ??


Top
 Profile  
 
 Post subject: Re: hibernate Problem .?
PostPosted: Fri Oct 28, 2011 5:42 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You have to tell Hibernate to create the schema... => hbm2ddl.auto
You have to name the hbm.xml-Files (like Event.hbm.xml)


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