Boa tarde, estou tentando fazer um relacionamento many to one no hibernate mas estou obtendo o erro Hibernate [Error getting Factory], bem Genérico neh?
Gostaria de mostrar meu arquivo de configuração e as classes para que talvez possam me ajudar a descobrir onde eu errei.
package com.sigga.common.map;
/*
* @see General
* @version 1.0
* @author Anderson dos Santos
* @data 05/05/2010
*/
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
/**
* Siggasm2Hgeneral generated by hbm2java
*/
@Entity
@Table(name = "SIGGASM2_HGENERAL")
public class General implements java.io.Serializable {
private String statusConcl;
private String statusAprv;
private String statusAbastece;
private String statusServico;
private boolean bloqueiaSincronismo;
private String orgid;
private String siteid;
private Collection<StatusDownload> statusDownloads;
private long hgeneralId;
public General() {
}
@Id
@Column(name = "HGENERAL_ID", unique = true, nullable = false, precision = 126, scale = 0)
public long getHgeneralId() {
return hgeneralId;
}
public void setHgeneralId(long hgeneralId) {
this.hgeneralId = hgeneralId;
}
@Column(name = "STATUS_CONCL", length = 30)
public String getStatusConcl() {
return this.statusConcl;
}
public void setStatusConcl(String statusConcl) {
this.statusConcl = statusConcl;
}
@Column(name = "STATUS_APRV", length = 30)
public String getStatusAprv() {
return this.statusAprv;
}
public void setStatusAprv(String statusAprv) {
this.statusAprv = statusAprv;
}
@Column(name = "STATUS_ABASTECE", length = 30)
public String getStatusAbastece() {
return this.statusAbastece;
}
public void setStatusAbastece(String statusAbastece) {
this.statusAbastece = statusAbastece;
}
@Column(name = "STATUS_SERVICO", length = 30)
public String getStatusServico() {
return this.statusServico;
}
public void setStatusServico(String statusServico) {
this.statusServico = statusServico;
}
@Column(name = "BLOQUEIA_SINCRONISMO", nullable = false, precision = 1, scale = 0)
public boolean isBloqueiaSincronismo() {
return this.bloqueiaSincronismo;
}
public void setBloqueiaSincronismo(boolean bloqueiaSincronismo) {
this.bloqueiaSincronismo = bloqueiaSincronismo;
}
@Column(name = "ORGID", nullable = false, length = 8)
public String getOrgid() {
return this.orgid;
}
public void setOrgid(String orgid) {
this.orgid = orgid;
}
@Column(name = "SITEID", nullable = false, length = 8)
public String getSiteid() {
return this.siteid;
}
public void setSiteid(String siteid) {
this.siteid = siteid;
}
/*** Relacionamento com a entidade StatusDonwload */
@OneToMany(mappedBy="general", fetch = FetchType.LAZY)
@Cascade(CascadeType.ALL)
public Collection<StatusDownload> getStatusDownloads() {
return statusDownloads;
}
public void setStatusDownloads(Collection<StatusDownload> statusDownloads) {
this.statusDownloads = statusDownloads;
}
}
package com.sigga.common.map;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
@Entity
@Table(name = "SIGGASM2_HSTATUS_DOWNLOAD")
public class StatusDownload implements Serializable{
private static final long serialVersionUID = 1L;
private long hstatusdonwloadId;
private String status;
private long hgeneralId;
private General general;
@Id
@Column(name="HSTATUS_DOWNLOADID", unique = true, nullable = false, precision = 126, scale = 0)
public long getHstatusdonwloadId() {
return hstatusdonwloadId;
}
public void setHstatusdonwloadId(long hstatusdonwloadId) {
this.hstatusdonwloadId = hstatusdonwloadId;
}
@Column(name="STATUS", nullable = false, length = 30)
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Id
@Column(name = "HGENERAL_ID", unique = true, nullable = false, precision = 126, scale = 0)
public long getHgeneralId() {
return hgeneralId;
}
public void setHgeneralId(long hgeneralId) {
this.hgeneralId = hgeneralId;
}
/*** Relacionamento com a entidade General ***/
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="HGENERAL_ID", nullable=false)
@Fetch(FetchMode.JOIN)
@Cascade(CascadeType.ALL)
public General getGeneral() {
return general;
}
public void setGeneral(General general) {
this.general = general;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">maximo</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.10.10.19:1521:MAXAPLAB</property>
<property name="hibernate.connection.username">maximo</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<mapping class="com.sigga.common.map.HandHeld"/>
<mapping class="com.sigga.common.map.Status"/>
<mapping class="com.sigga.common.map.Locations"/>
<mapping class="com.sigga.common.map.Material"/>
<mapping class="com.sigga.common.map.Users"/>
<mapping class="com.sigga.common.map.Organization"/>
<!-- Classe que acontece o erro-->
<mapping class="com.sigga.common.map.General"/>
<mapping class="com.sigga.common.map.StatusDownload"/>
</session-factory>
</hibernate-configuration>
TESTE:
public void testJoin(){
Object owner = null;
Session session = null;
try{
// ------------> O Erro Acontece Na Prox. Linha <-----------------------
owner = HibernateSession.createSession();
session = HibernateSession.getSession();
General general = (General) session.get(General.class, 1);
Iterator<StatusDownload> it = general.getStatusDownloads().iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}catch (Exception e) {
e.printStackTrace();
}
finally{
try {
HibernateSession.closeSession(owner);
} catch (Exception e) {
e.printStackTrace();
}
}
}
E o mais intrigante eh que em outros locais uso o mesmo teste para entidades diferentes e não funciona, porem se tirar do mapeamento do hibernate da classe General e StatusDonwload consigo criar a sessao normalmente.
O ERRO ESTAVA NO NOME DA COLUNA
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name=“HGENERAL_ID”, nullable=false)
TROQUEI PELO ATRIBUTO
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name=“hgeneralId”, nullable=false)
e FUNCIONOU!!!
