-->
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 hbm2ddl error with Apache Derby Embedded
PostPosted: Mon Mar 06, 2006 8:42 pm 
Newbie

Joined: Mon Jun 20, 2005 11:07 am
Posts: 16
Hibernate version:3.1.2

Full stack trace of any exception that occurs:

[Pousada Control] INFO [main] TipoLeitoDAOTest.loadContextLocations(119) | Loading config for: classpath*:applicationContext-jdbc.xml,classpath*:applicationContext-dao.xml
[Pousada Control] ERROR [main] SchemaUpdate.execute(157) | Unsuccessful: create table CLIENTES.LEITO_LTO (ID_LTO bigint not null generated always as identity unique, DESCRICAO varchar(80) not null unique, NUMERO varchar(10), ID_TLT bigint, primary key (ID_LTO))
[Pousada Control] ERROR [main] SchemaUpdate.execute(158) | Constraints 'SQL060306091632712' and 'SQL060306091632710' have the same set of columns, which is not allowed.
[Pousada Control] ERROR [main] SchemaUpdate.execute(157) | Unsuccessful: create table CLIENTES.TIPO_LEITO_TLT (ID_TLT bigint not null generated always as identity unique, DESCRICAO varchar(80) not null unique, primary key (ID_TLT))
[Pousada Control] ERROR [main] SchemaUpdate.execute(158) | Constraints 'SQL060306091632762' and 'SQL060306091632760' have the same set of columns, which is not allowed.
[Pousada Control] ERROR [main] SchemaUpdate.execute(157) | Unsuccessful: alter table CLIENTES.LEITO_LTO add constraint FKAD859DF38B1188A5 foreign key (ID_TLT) references CLIENTES.TIPO_LEITO_TLT
[Pousada Control] ERROR [main] SchemaUpdate.execute(158) | Schema 'CLIENTES' does not exist
[Pousada Control] INFO [main] TipoLeitoDAOTest.onSetUp(108) | Began transaction: transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@10e6cbd]; defaultRollback true


Name and version of the database you are using: Apache Derby 1.0.1 Embedded mode

I'm trying to generate the schema from POJOs using Hibernate Annotations 3.1 beta 8 with Spring 1.2.7. I don't know why derby doesn't allow the schema creation. Is something wrong with these???
PS - In MySQL everything works fine



Classes:

package com.pousadacontrol.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
*
* Classe responsável por representar o domínio do Leito no negócio
*
* @author rafaji
*
*/
@Entity
@Table(name = "LEITO_LTO", schema = "CLIENTES")
public class Leito extends ObjetoBase {

/**
*
*/
private static final long serialVersionUID = -7838656155808091415L;

/**
* Atributo responsável por representar o código do leito
*/
private Long id;

/**
* Atributo responsável por representar o tipo do leito do leito
*/
private TipoLeito tipoLeito = new TipoLeito();

/**
* Atributo responsável por representar a descrição do leito
*/
private String descricao;

/**
* Atributo responsável por representar o número do leito
*/
private String numero;

/**
* Construtor padrão da classe Leito
*/
public Leito()
{
}

/**
* Construtor mínimo da classe Leito
*
* @param descricao
* @param numero
* @param tipoLeitoId
*/
public Leito(String descricao, String numero, Long tipoLeitoId)
{
this.descricao = descricao;
this.numero = numero;
this.tipoLeito.setId(tipoLeitoId);
}

/**
* Construtor completo da classe Leito
*
* @param id
* @param descricao
* @param numero
* @param tipoLeito
*/
public Leito(Long id, String descricao, String numero, TipoLeito tipoLeito)
{
this.id = id;
this.descricao = descricao;
this.numero = numero;
this.tipoLeito = tipoLeito;
}

/**
* Método de acesso ao atributo descrição
*
* @return
*/
@Column(name = "DESCRICAO", nullable = false, unique = true, length = 80)
public String getDescricao()
{
return descricao;
}

/**
* Método de modificação do atributo descrição
*
* @param descricao
*/
public void setDescricao(String descricao)
{
this.descricao = descricao;
}

/**
* Método de acesso ao atributo id
*
* @return
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_LTO", nullable = false, unique = true, length = 11)
public Long getId()
{
return id;
}

/**
* Método de modificação do atributo id
*
* @param id
*/
public void setId(Long id)
{
this.id = id;
}

/**
* Método de acesso ao atributo número
*
* @return
*/
@Column(name = "NUMERO", nullable = true, unique = false, length = 10)
public String getNumero()
{
return numero;
}

/**
* Método de modificação do atributo número
*
* @param numero
*/
public void setNumero(String numero)
{
this.numero = numero;
}

/**
* Método de acesso ao atributo tipoLeito
*
* @return
*/
@ManyToOne
@JoinColumn(name = "ID_TLT")
public TipoLeito getTipoLeito()
{
return tipoLeito;
}

/**
* Método de modificação do atributo tipoLeito
*
* @param tipoLeito
*/
public void setTipoLeito(TipoLeito tipoLeito)
{
this.tipoLeito = tipoLeito;
}

@Override
public int hashCode()
{
return this.id != null ? id.hashCode() : 0;
}

@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof Leito))
return false;

final Leito l = (Leito) o;
if (id != null ? !id.equals(l.getId()) : l.getId() != null)
return false;
return true;
}

@Override
public String toString()
{
return "CÓDIGO - " + id + "\nDESCRICAO - " + descricao + "\nTIPOLEITO - " + tipoLeito + "\nNUMERO - " + numero;
}

}


package com.pousadacontrol.model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
*
* Classe responsável por representar um domínio de Tipo de Leito na aplicação
*
* @author rafaji
*
*/
@Entity
@Table(name = "TIPO_LEITO_TLT", schema = "CLIENTES")
public class TipoLeito extends ObjetoBase {

/**
*
*/
private static final long serialVersionUID = 5628613569444905584L;

/**
* Atributo responsável por representar o código do tipo do leito
*/
private Long id;

/**
* Atributo responsável por representar a descrição do tipo do leito
*/
private String descricao;

/**
* Atributo responsável por representar os leitos do tipo leito.
*/
private Set<Leito> leitos;

/**
* Construtor padrão da classe TipoLeito
*/
public TipoLeito()
{
}

/**
* Construtor mínimo da classe TipoLeito
*
* @param descricao
*/
public TipoLeito(String descricao)
{
this.descricao = descricao;
}

/**
* Construtor completo da classe TipoLeito
*
* @param id
* @param descricao
* @param leitos
*/
public TipoLeito(Long id, String descricao, Set<Leito> leitos)
{
this.id = id;
this.descricao = descricao;
this.leitos = leitos;
}

/**
* Método de acesso ao atributo descrição
*
* @return
*/
@Column(name = "DESCRICAO", nullable = false, unique = true, length = 80)
public String getDescricao()
{
return descricao;
}

/**
* Método de modificação do atributo descrição
*
* @param descricao
*/
public void setDescricao(String descricao)
{
this.descricao = descricao;
}

/**
* Método de acesso ao atributo id
*
* @return
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_TLT", nullable = false, unique = true, length = 11)
public Long getId()
{
return id;
}

/**
* Método de modificação do atributo id
*
* @param id
*/
public void setId(Long id)
{
this.id = id;
}

/**
* Método de acesso ao atributo leitos
*
* @return
*/
@OneToMany(mappedBy = "tipoLeito")
public Set<Leito> getLeitos()
{
return leitos;
}

/**
* Método de modificação do atributo leitos
*
* @param leitos
*/
public void setLeitos(Set<Leito> leitos)
{
this.leitos = leitos;
}

@Override
public int hashCode()
{
return this.id != null ? this.id.hashCode() : 0;
}

@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof TipoLeito))
return false;

final TipoLeito tl = (TipoLeito) o;
if (id != null ? !id.equals(tl.getId()) : tl.getId() != null)
return false;
return true;
}

@Override
public String toString()
{
return "CÓDIGO - " + id + "\nDESCRICAO - " + descricao + "\nLEITOS - " + leitos;
}

}




Hibernate Configuration File

<!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="com.pousadacontrol.model.Leito" />
<mapping class="com.pousadacontrol.model.TipoLeito" />
</session-factory>
</hibernate-configuration>





applicationContext-jdbc.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName">
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
</property>
<property name="url">
<value>jdbc:derby:C:/data/jturclient</value>
</property>
<property name="username">
<value>APP</value>
</property>
<property name="password">
<value>APP</value>
</property>
</bean>
</beans>





applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>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.DerbyDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<bean id="dao"
class="com.pousadacontrol.dao.hibernate.BaseDAOHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="usuarioDAO"
class="com.pousadacontrol.dao.hibernate.UsuarioDAOHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="papelDAO"
class="com.pousadacontrol.dao.hibernate.PapelDAOHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="tipoLeitoDAO"
class="com.pousadacontrol.dao.hibernate.TipoLeitoDAOHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>



Thanks in advance

Rafael Mauricio Nami


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 11:58 am 
Newbie

Joined: Mon Jun 20, 2005 11:07 am
Posts: 16
JESUS CHRIST, IT WORKED!!!! HALLLELLUYAHH!!!!
Just had to put the attributes in @Table in lowercase ;)


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.