Olá amigos do GUJ, venho perdir um HELP…
Estou com um probleminha na hora de mapear minha classe com Annotations.
Tenho duas classes Usuario e Perfil, na qual quero associar Usuario à Perfil.
package Model;
import java.io.Serializable;
import java.util.*;
import javax.persistence.*;
@Entity
@Table(name="PERFIL")
public class Perfil extends NO implements Serializable {
@Column(name="NOME")
private String nome;
@Temporal(TemporalType.DATE)
@Column(name="NASCIMENTO")
private Date nascimento;
@Column(name="SEXO")
private char sexo;
@OneToOne(cascade=CascadeType.ALL, optional=false )
@JoinColumn(name = "USUARIO_ID")
private Usuario usuario;
public Perfil(){/*empty constructor*/}
// gets and sets omitidos....
}
E na classe Usuario não coloco nada referente ao relacionamento. Só @entity @Id e por ai vai…
A ideia é que cada classe tenha uma respectiva tabela no banco de dados.
porém o que está acontecendo é que ao gerar as tabelas no banco, a tabela perfil ao inves de ter uma chave estrangeira para a tabela usuario, está sendo gerado um campo Usuario do tipo TyniBlob que armazena as informações de usuario.
Bom já tentei N notações diferentes tipo
@PrimaryKeyJoinColumn(name = “USUARIO_ID”)
@SecondaryTable…
somente @OneToOne
porém nada mudou, ele continua gerando o campo usuario na tabela perfil.
O que estou tentando agora é desabilitar a geração automatica de tabelas. Criei a tabela na mão e to tentando persistir nela, só que ele reclama que o campo usuario não existe…
26/11/2009 17:58:49 org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
26/11/2009 17:58:49 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
26/11/2009 17:58:49 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
26/11/2009 17:58:49 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
26/11/2009 17:58:49 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
26/11/2009 17:58:49 org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.2.GA
26/11/2009 17:58:49 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: Model.Grupo
26/11/2009 17:58:49 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity Model.Grupo on table Grupo
26/11/2009 17:58:49 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: Model.Usuario
26/11/2009 17:58:49 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity Model.Usuario on table USUARIO
26/11/2009 17:58:49 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: Model.Perfil
26/11/2009 17:58:49 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity Model.Perfil on table PERFIL
26/11/2009 17:58:49 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
26/11/2009 17:58:49 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
26/11/2009 17:58:49 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
26/11/2009 17:58:49 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
26/11/2009 17:58:49 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/cubix-base
26/11/2009 17:58:49 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.1.38-community
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
26/11/2009 17:58:49 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
26/11/2009 17:58:49 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
26/11/2009 17:58:49 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
26/11/2009 17:58:49 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: enabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
26/11/2009 17:58:49 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
26/11/2009 17:58:49 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
26/11/2009 17:58:50 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
26/11/2009 17:58:50 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1054, SQLState: 42S22
26/11/2009 17:58:50 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Unknown column ‘usuario’ in ‘field list’
[color=blue]
Estou usando o Netbens 6.5 e as bibliotecas são todas as que vieram com ele, Hibernate-JPA e MySQL JDBC driver.
Preciso de uma luz amigos… pois já li diversos post, tutoriais, javados e me parece que o meu mapeamento está correto porém o resultado não está…
[/color]