-->
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: Hibernate Annotations (hbm2ddl)
PostPosted: Thu Oct 09, 2008 4:43 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
I'm doing a tutorial which uses spring + Hibernate Annotations ... I use log4j.properties to help me see the loggers. I get a ERROR log which states "Unsuccessful: create table myobject(...)" Error location being "org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:325)"

Qs.

1. I noticed on the tutorial, there's no where a table is created on the DB, so i assume hibernate does this by using hbm2ddl.. Where is this located and where does one normally tell hibernate to invoke this function

2. I also have a DEBUG logger "import file not found: /import.sql" also pointing to the same location ... Am really lost as to where these configurations are done on my application

here's my hibernate.cfg.xml

Code:
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping class="org.annotationmvc.vo.MyObjectVO"/>
    </session-factory>
</hibernate-configuration>



and here's my POJO
Code:
package org.annotationmvc.vo;

import java.io.*;
import javax.persistence.*;


@Entity
@Table (name="myobject")
public class MyObjectVO implements Serializable {

    private int id;
    private String name;
    private String address;
    private String email;
    private String phone;

    public MyObjectVO() {
    }

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

    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setEmail(String email) {
        this.email = email;
    }

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

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    //@Id (generate = GeneratorType.AUTO)
    public int getId() {
        return id;
    }

    @Column (length=100)
    public String getName() {
        return name;
    }

    @Column (length=100)
    public String getAddress() {
        return address;
    }

    @Column (length=30)
    public String getEmail() {
        return email;
    }

    @Column (length=15)
    public String getPhone() {
        return phone;
    }
}


I'm sure this line "@Table (name="myobject")" expects the table to exist already, but where exactly is/should the creation of the table be?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 7:33 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
ok, i found this call inside applicationContext-dao.xml

Code:
  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="configLocation"><value>WEB-INF/hibernate.cfg.xml</value></property>
    <property name="configurationClass"><value>org.hibernate.cfg.AnnotationConfiguration</value></property>
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
[b]        <prop key="hibernate.hbm2ddl.auto">create</prop>[/b]
      </props>
    </property>
  </bean>

but not sure where hubernate.hbm2ddl is located because i would like to tract these logged messages

- "drop table myobject cascade constraints"
- "Unsuccessful: drop table myobject ...
- "create table myobject (id number(10,0) ....
- "Unsuccessful: create table myobject ....
- "ORA-00907: missing right parenthesis where exactly is this done?????


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 10:26 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
As i'm reading through trying to solve my problem, i came across the file import.sql which the tutorial does not introduce at all ... Should one always have this file to use hbm2ddl? I wish i cud get an answer on this problem cause its strange that the error is "missing parenthesis" whilst i'm not even responsible for the HQL query for creating the table myobject, not even sure where its located!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 10:32 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
As i'm reading through trying to solve my problem, i came across the file import.sql which the tutorial does not introduce at all ... Should one always have this file to use hbm2ddl? I wish i cud get an answer on this problem cause its strange that the error is "missing parenthesis" whilst i'm not even responsible for the HQL query for creating the table myobject, not even sure where its located!!!!


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.