drsmachado 19 de set. de 2013
O problema é que você faz uma pergunta sem dar todas as informações necessárias.
Qual o “problema”? Onde ocorre?
diogogama 19 de set. de 2013
Aí é difícil ajudar hein… rs…
Guguuu 19 de set. de 2013
Erro
log4j : WARN No appenders could be found for logger ( org . hibernate . cfg . annotations . Version ).
log4j : WARN Please initialize the log4j system properly .
Exception in thread "main" org . hibernate . AnnotationException : @ OneToOne or @ ManyToOne on br . com . SIP . Model . Usuario . perfil references an unknown entity : br . com . SIP . Model . Perfil
at org . hibernate . cfg . ToOneFkSecondPass . doSecondPass ( ToOneFkSecondPass . java : 81 )
at org . hibernate . cfg . AnnotationConfiguration . processEndOfQueue ( AnnotationConfiguration . java : 456 )
at org . hibernate . cfg . AnnotationConfiguration . processFkSecondPassInOrder ( AnnotationConfiguration . java : 438 )
at org . hibernate . cfg . AnnotationConfiguration . secondPassCompile ( AnnotationConfiguration . java : 309 )
at org . hibernate . cfg . Configuration . generateDropSchemaScript ( Configuration . java : 789 )
at org . hibernate . tool . hbm2ddl . SchemaExport .< init >( SchemaExport . java : 128 )
at org . hibernate . tool . hbm2ddl . SchemaExport .< init >( SchemaExport . java : 91 )
at br . com . SIP . Util . GeraBancoUtilSIP . main ( GeraBancoUtilSIP . java : 16 )
Estou tentando gerar o banco!!
drsmachado 19 de set. de 2013
Então…
O erro diz que a entidade br.com.SIP.Model.Perfil não é uma entidade (ela não foi mapeada).
leonhard32 19 de set. de 2013
Guguuu:
Estou com uma duvida de herança + hibernate
Criei minha classe normal... ae fui colocar um objeto @manytoone e ta dando problema...
@Entity
# Perfil
- nivel
- nome
- @OneToMany ( mappedBy = "perfil" , fetch = FetchType . LAZY )
private List < Usuario > usuarios ;
@Entity
@Inheritance ( strategy = InheritanceType . SINGLE_TABLE )
@DiscriminatorColumn ()
# Pessoa
- id
- nome
- ...
@Entity
# Funcionario extende Pessoa
- senha
- usuario
- @ManyToOne
private Perfil perfil ;
Na classe Perfil você maepa uma lista de usuarios, porém usando o 'mappedBy' o hibernate espera achar o 'perfil' na classe Usuário, mas está no Funcionario...
Um dos erros deve ser esse, agora se tem mais algum... rs
[]'s
Guguuu 19 de set. de 2013
Desculpe Digitei errado… vou colar a classe para nao dar mais problema. DESCULPEM
Classe Perfil
@Entity
public class Perfil {
@Id
@GeneratedValue
private Long id ;
private String nome ;
private String permissao ;
@OneToMany ( mappedBy = "perfil" , fetch = FetchType . LAZY )
private List < Usuario > usuarios ;
@Type ( type = "true_false" )
private boolean status ;
Classe Pessoa
@Entity
@Inheritance ( strategy = InheritanceType . SINGLE_TABLE )
@DiscriminatorColumn ()
public class Pessoa {
@Id
@GeneratedValue
private Long id ;
private String nome ;
@ManyToOne
private Endereco endereco ;
private String cpf ;
private String rg ;
private String telefone ;
private String celular ;
Classe Usuario
@Entity
public class Usuario extends Pessoa {
private String matricula ;
private String usuario ;
private String senha ;
@ManyToOne
private Perfil perfil ;
leonhard32 19 de set. de 2013
Guguuu:
Desculpe Digitei errado... vou colar a classe para nao dar mais problema. DESCULPEM
Classe Perfil
@Entity
public class Perfil {
@Id
@GeneratedValue
private Long id ;
private String nome ;
private String permissao ;
@OneToMany ( mappedBy = "perfil" , fetch = FetchType . LAZY )
private List < Usuario > usuarios ;
@Type ( type = "true_false" )
private boolean status ;
Classe Pessoa
@Entity
@Inheritance ( strategy = InheritanceType . SINGLE_TABLE )
@DiscriminatorColumn ()
public class Pessoa {
@Id
@GeneratedValue
private Long id ;
private String nome ;
@ManyToOne
private Endereco endereco ;
private String cpf ;
private String rg ;
private String telefone ;
private String celular ;
Classe Usuario
@Entity
public class Usuario extends Pessoa {
private String matricula ;
private String usuario ;
private String senha ;
@ManyToOne
private Perfil perfil ;
Uma pergunta, algum motivo especial para não ter criado uma coluna para distinção das classes que herdam de Pessoa?
Tipo,na classe Pessoa:
@DiscriminatorColumn (
name = "tipo" ,
discriminatorType = DiscriminatorType . STRING
)
@DiscriminatorValue ( "Pessoa" )
E na classe Usuario:
@DiscriminatorValue ( "Usuario" )
[]'s
drsmachado 19 de set. de 2013
leonhard32:
Guguuu:
Desculpe Digitei errado... vou colar a classe para nao dar mais problema. DESCULPEM
Classe Perfil
@Entity
public class Perfil {
@Id
@GeneratedValue
private Long id ;
private String nome ;
private String permissao ;
@OneToMany ( mappedBy = "perfil" , fetch = FetchType . LAZY )
private List < Usuario > usuarios ;
@Type ( type = "true_false" )
private boolean status ;
Classe Pessoa
@Entity
@Inheritance ( strategy = InheritanceType . SINGLE_TABLE )
@DiscriminatorColumn ()
public class Pessoa {
@Id
@GeneratedValue
private Long id ;
private String nome ;
@ManyToOne
private Endereco endereco ;
private String cpf ;
private String rg ;
private String telefone ;
private String celular ;
Classe Usuario
@Entity
public class Usuario extends Pessoa {
private String matricula ;
private String usuario ;
private String senha ;
@ManyToOne
private Perfil perfil ;
Uma pergunta, algum motivo especial para não ter criado uma coluna para distinção das classes que herdam de Pessoa?
Tipo,na classe Pessoa:
@DiscriminatorColumn (
name = "tipo" ,
discriminatorType = DiscriminatorType . STRING
)
@DiscriminatorValue ( "Pessoa" )
E na classe Usuario:
@DiscriminatorValue ( "Usuario" )
[]'s
Quando este atributo (coluna) é omitido, o hibernate não o cria automagicamente?
leonhard32 19 de set. de 2013
drsmachado:
leonhard32:
Guguuu:
Desculpe Digitei errado... vou colar a classe para nao dar mais problema. DESCULPEM
Classe Perfil
@Entity
public class Perfil {
@Id
@GeneratedValue
private Long id ;
private String nome ;
private String permissao ;
@OneToMany ( mappedBy = "perfil" , fetch = FetchType . LAZY )
private List < Usuario > usuarios ;
@Type ( type = "true_false" )
private boolean status ;
Classe Pessoa
@Entity
@Inheritance ( strategy = InheritanceType . SINGLE_TABLE )
@DiscriminatorColumn ()
public class Pessoa {
@Id
@GeneratedValue
private Long id ;
private String nome ;
@ManyToOne
private Endereco endereco ;
private String cpf ;
private String rg ;
private String telefone ;
private String celular ;
Classe Usuario
@Entity
public class Usuario extends Pessoa {
private String matricula ;
private String usuario ;
private String senha ;
@ManyToOne
private Perfil perfil ;
Uma pergunta, algum motivo especial para não ter criado uma coluna para distinção das classes que herdam de Pessoa?
Tipo,na classe Pessoa:
@DiscriminatorColumn (
name = "tipo" ,
discriminatorType = DiscriminatorType . STRING
)
@DiscriminatorValue ( "Pessoa" )
E na classe Usuario:
@DiscriminatorValue ( "Usuario" )
[]'s
Quando este atributo (coluna) é omitido, o hibernate não o cria automagicamente?
Cara, não me lembro viu, na sua tabela foi gerada esta coluna?
[]'s
drsmachado 19 de set. de 2013
leonhard32:
Cara, não me lembro viu, na sua tabela foi gerada esta coluna?
[]'s
Eu também não lembro, mas creio que ele faça isso.