none
How to connect a maven project to SQL Server 2008 Database using Java Hibernate with Eclipse?

    Question

  • Hi guys

    I'm used to connecting a database in java using normal java code, I'm working on a project for my company, I'm using Eclipse, I have a maven Project as the back-end and have a ramp(VMT [Mobile Framework] ) project as the front-end. Requirements is for me to use Hibernate, i'm new to this kind of database connectivity, I'm using tomcat 5.5 and my files need to point to each other in the right way(which is where i get lost) , so far i have gathered examples from the net this is what intend to do:

    my *.cfg.xml is as follows:

    <?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">org.hsqldb.jdbcDriver</property>
    
    <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
    
    <property name="connection.username">sa</property>
    
    <property name="connection.password"></property>
    
    
    <!-- JDBC connection pool (use the built-in) -->
    
    <property name="connection.pool_size">1</property>
    
    
    <!-- SQL dialect -->
    
    <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
    
    
    <!-- Enable Hibernate's automatic session context management -->
    
    <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">update</property>
    
    <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
    
    
    </session-factory>
    
    </hibernate-configuration>
    
    
    

    My *.hbm.xml is as follows:

    <?xml version="1.0"?>
    
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
    <!-- Generated 08 Jul 2010 1:22:21 PM by Hibernate Tools 3.3.0.GA -->
    
    <hibernate-mapping package="org.hibernate.tutorial.domain">
    
    
    <class name="Event" table="EVENTS">
    
    <id name="id" column="EVENT_ID">
    
    <generator class="native"/>
    
    </id>
    
    <property name="date" type="timestamp" column="EVENT_DATE"/>
    
    <property name="title"/>
    
    </class>
    
    
    </hibernate-mapping>
    
    
    

    my datasource:

    <datasources>
       <xa-datasource>
         <jndi-name>timesheet-DS</jndi-name>
         <xa-datasource-property name="URL">jdbc:microsoft:sqlserver://localhost:1433;databasename=Timesheet</xa-datasource-property> 
         <user-name>root</user-name>
         <password>dvtjava</password>
         <track-connection-by-tx>true</track-connection-by-tx>
         <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
         <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
         <min-pool-size>1</min-pool-size>
         <max-pool-size>10</max-pool-size>
         <idle-timeout-minutes>10</idle-timeout-minutes>
         <metadata>
           <type-mapping>mySQL</type-mapping>
         </metadata>
       </xa-datasource>
     </datasources>
    
    
    

    CAN ANYONE ADVISE ME?

    Friday, July 09, 2010 9:31 AM

Answers