@id hibernate annotation

2 respostas
K

Pessoal,

Como eu mapeio um ID do tipo String e que não usa Generetor.
Tenho uma Clase com a seguinte estrutura:

@Entity
@Table
public class Usuario implements Serializable {

private String matricula;
private String nome;	
private Unidade unidade;
private Integer idNivel;


public String toString(){
	return this.matricula + ": " + this.nome;
}

@Id 
public String getMatricula() {
	return matricula;
}
public void setMatricula(String matricula) {
	this.matricula = matricula;
}

public String getNome() {
	return nome;
}
public void setNome(String nome) {
	this.nome = nome;
}


@ManyToOne @JoinColumn(name="id_unidade")
public Unidade getUnidade() {
	return unidade;
}
public void setUnidade(Unidade unidade) {
	this.unidade = unidade;
}


@Column(name="id_nivel")
public Integer getIdNivel() {
	return idNivel;
}
public void setIdNivel(Integer idNivel) {
	this.idNivel = idNivel;
}

}

Notem que o meu ID é um String e não uso generator.

Quando eu faço uma consulta esta me retornando o seguinte erro:

Hibernate: select this_.matricula as matricula0_1_, this_.nome as nome0_1_, this_.id_unidade as id6_0_1_, this_.id_nivel as id4_0_1_, this_.email as email0_1_, this_.DTYPE as DTYPE0_1_, unidade2_.id as id1_0_, unidade2_.nome as nome1_0_, unidade2_.cgc as cgc1_0_, unidade2_.endereco as endereco1_0_ from Usuario this_ left outer join Unidade unidade2_ on this_.id_unidade=unidade2_.id where (1=1) limit ?

org.hibernate.exception.SQLGrammarException: could not execute query

at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

at org.hibernate.loader.Loader.doList(Loader.java:2147)

at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)

at org.hibernate.loader.Loader.list(Loader.java:2023)

at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)

at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)

at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)

at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)

at persistencia.hibernate.UsuarioHibernate.consuntar(UsuarioHibernate.java:32)

at Teste.main(Teste.java:21)

Caused by: org.postgresql.util.PSQLException: ERROR: column this_.dtype does not exist

at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)

at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)

at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)

at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:437)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:353)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:257)

at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)

at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)

at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)

at org.hibernate.loader.Loader.doQuery(Loader.java:662)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)

at org.hibernate.loader.Loader.doList(Loader.java:2144)

 8 more

Acredito que o erro ta no tipo do ID, o select retornado tem um TYPE.
Se eu consulto uma unidade e através dela eu consigo listar os usuários, mas do outro lado eu não consigo por causa da chave!!

Valeu

Antonio

2 Respostas

P

Acho que isso da certo.

@Id
@GeneratedValue(startegy=GenerationType.AUTO)

mais posso estar enganado.

K

poiati:
Acho que isso da certo.

@Id
@GeneratedValue(startegy=GenerationType.AUTO)

mais posso estar enganado.

poiati,
valeu pela dica mas infelizmente nao resolvel!!!

algem se arisca???

abraços

Antonio

Criado 16 de novembro de 2006
Ultima resposta 16 de nov. de 2006
Respostas 2
Participantes 2