2015-11-04 89 views
1

我想映射我的表與Hibernate的工作,但是當我啓動測試時出現此錯誤。休眠:未知mappedBy在:,引用屬性未知:

Nov 04, 2015 5:17:40 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager 
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 
Nov 04, 2015 5:17:41 PM org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {4.3.8.Final} 
Nov 04, 2015 5:17:41 PM org.hibernate.cfg.Environment <clinit> 
INFO: HHH000206: hibernate.properties not found 
Nov 04, 2015 5:17:41 PM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 
Nov 04, 2015 5:17:41 PM org.hibernate.cfg.Configuration configure 
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 
Nov 04, 2015 5:17:41 PM org.hibernate.cfg.Configuration getConfigurationInputStream 
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 
Nov 04, 2015 5:17:41 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity 
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! 
Nov 04, 2015 5:17:41 PM org.hibernate.cfg.Configuration doConfigure 
INFO: HHH000041: Configured SessionFactory: null 
Nov 04, 2015 5:17:41 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 
Nov 04, 2015 5:17:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 
INFO: HHH000401: using driver [oracle.jdbc.OracleDriver] at URL [jdbc:oracle:thin:@c0fspost0.internal.unicreditgroup.eu:1521/c0fspost0] 
Nov 04, 2015 5:17:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 
INFO: HHH000046: Connection properties: {user=TFSPC000, password=****} 
Nov 04, 2015 5:17:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 
INFO: HHH000006: Autocommit mode: false 
Nov 04, 2015 5:17:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 
Nov 04, 2015 5:17:44 PM org.hibernate.dialect.Dialect <init> 
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect 
SessionFactory creation failed.org.hibernate.AnnotationException: Unknown mappedBy in: it.addvalue.mam.fpk.alertengine.mapping.TEvents.TEventsDetails, referenced property unknown: it.addvalue.mam.fpk.alertengine.mapping.TEventsDetails.tEvents 

在這裏有我的映射類

package it.addvalue.mam.fpk.alertengine.mapping; // default package 
// Generated Nov 4, 2015 3:02:28 PM by Hibernate Tools 3.4.0.CR1 

import java.math.BigDecimal; 
import java.sql.Timestamp; 
import java.util.HashSet; 
import java.util.Set; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.Id; 
import javax.persistence.OneToMany; 
import javax.persistence.OneToOne; 
import javax.persistence.Table; 

/** 
* TEvents generated by hbm2java 
*/ 
@Entity 
@Table(name = "T_EVENTS") 
public class TEvents implements java.io.Serializable { 

    private BigDecimal eventId; 
    private Timestamp tsEvent; 
    private String object; 
    private String objectFase; 
    private String tipoEvento; 
    private Set<TEventsSent> TEventsSents = new HashSet<TEventsSent>(0); 
    private TEventsDetails TEventsDetails; 

    public TEvents() { 
    } 

    public TEvents(BigDecimal eventId, Timestamp tsEvent, String object, 
      String objectFase, String tipoEvento) { 
     this.eventId = eventId; 
     this.tsEvent = tsEvent; 
     this.object = object; 
     this.objectFase = objectFase; 
     this.tipoEvento = tipoEvento; 
    } 

    public TEvents(BigDecimal eventId, Timestamp tsEvent, String object, 
      String objectFase, String tipoEvento, 
      Set<TEventsSent> TEventsSents, TEventsDetails TEventsDetails) { 
     this.eventId = eventId; 
     this.tsEvent = tsEvent; 
     this.object = object; 
     this.objectFase = objectFase; 
     this.tipoEvento = tipoEvento; 
     this.TEventsSents = TEventsSents; 
     this.TEventsDetails = TEventsDetails; 
    } 

    @Id 
    @Column(name = "EVENT_ID", unique = true, nullable = false, scale = 0) 
    public BigDecimal getEventId() { 
     return this.eventId; 
    } 

    public void setEventId(BigDecimal eventId) { 
     this.eventId = eventId; 
    } 

    @Column(name = "TS_EVENT", nullable = false) 
    public Timestamp getTsEvent() { 
     return this.tsEvent; 
    } 

    public void setTsEvent(Timestamp tsEvent) { 
     this.tsEvent = tsEvent; 
    } 

    @Column(name = "OBJECT", nullable = false, length = 100) 
    public String getObject() { 
     return this.object; 
    } 

    public void setObject(String object) { 
     this.object = object; 
    } 

    @Column(name = "OBJECT_FASE", nullable = false, length = 100) 
    public String getObjectFase() { 
     return this.objectFase; 
    } 

    public void setObjectFase(String objectFase) { 
     this.objectFase = objectFase; 
    } 

    @Column(name = "TIPO_EVENTO", nullable = false, length = 3) 
    public String getTipoEvento() { 
     return this.tipoEvento; 
    } 

    public void setTipoEvento(String tipoEvento) { 
     this.tipoEvento = tipoEvento; 
    } 

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "TEvents") 
    public Set<TEventsSent> getTEventsSents() { 
     return this.TEventsSents; 
    } 

    public void setTEventsSents(Set<TEventsSent> TEventsSents) { 
     this.TEventsSents = TEventsSents; 
    } 

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "tEvents") 
    public TEventsDetails getTEventsDetails() { 
     return this.TEventsDetails; 
    } 

    public void setTEventsDetails(TEventsDetails TEventsDetails) { 
     this.TEventsDetails = TEventsDetails; 
    } 

} 

另一種

package it.addvalue.mam.fpk.alertengine.mapping; // default package 
// Generated Nov 4, 2015 3:02:28 PM by Hibernate Tools 3.4.0.CR1 

import java.math.BigDecimal; 
import java.sql.Blob; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.OneToOne; 
import javax.persistence.PrimaryKeyJoinColumn; 
import javax.persistence.Table; 
import org.hibernate.annotations.GenericGenerator; 
import org.hibernate.annotations.Parameter; 

/** 
* TEventsDetails generated by hbm2java 
*/ 
@Entity 
@Table(name = "T_EVENTS_DETAILS") 
public class TEventsDetails implements java.io.Serializable { 

    private BigDecimal eventId; 
    private TEvents TEvents; 
    private Blob detail; 

    public TEventsDetails() { 
    } 

    public TEventsDetails(TEvents TEvents, Blob detail) { 
     this.TEvents = TEvents; 
     this.detail = detail; 
    } 

    @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "TEvents")) 
    @Id 
    @GeneratedValue(generator = "generator") 
    @Column(name = "EVENT_ID", unique = true, nullable = false, scale = 0) 
    public BigDecimal getEventId() { 
     return this.eventId; 
    } 

    public void setEventId(BigDecimal eventId) { 
     this.eventId = eventId; 
    } 

    @OneToOne(fetch = FetchType.LAZY) 
    @PrimaryKeyJoinColumn 
    public TEvents getTEvents() { 
     return this.TEvents; 
    } 

    public void setTEvents(TEvents TEvents) { 
     this.TEvents = TEvents; 
    } 

    @Column(name = "DETAIL", nullable = false) 
    public Blob getDetail() { 
     return this.detail; 
    } 

    public void setDetail(Blob detail) { 
     this.detail = detail; 
    } 

} 

任何建議來解決這個問題?映射,對我來說是正確的,也因爲它是由Hibernate自動生成

+0

什麼是私人TEventsDetails TEventsDetails的映射; ?另外,用小寫字母開始變量名會更好些... – tom

+0

Hibernate Code Generation做了這個工作,我同意你的小寫。 回答你的問題: @OneToOne(fetch = FetchType.LAZY,mappedBy =「tEvents」) public TEventsDetails getTEventsDetails(){ return this.TEventsDetails; } – depa

回答

0

你應該從TEvents更改TEvents變量名tEvents:

public class TEventsDetails implements java.io.Serializable { 

..... 

private TEvents tEvents; 

public TEvents getTEvents() { 
    return this.tEvents; 
} 

public void setTEvents(TEvents TEvents) { 
    this.tEvents = TEvents; 
} 
..... 

}

+0

我做到了,但錯誤只是 SessionFactory的創建failed.org.hibernate.AnnotationException改變:未知的mappedBy在:it.addvalue.mam.fpk.alertengine.mapping.TEvents.TEventsDetails,引用未知屬性:它.addvalue.mam.fpk.alertengine.mapping.TEventsDetails.tEvents – depa

0

請定義列名在class TEventsDetails的以下行中,因爲您已經定義了TEventsDetails表的哪些列與TEvents表相關聯。

@JoinColumn(name = "EVENT_ID") 
+0

據相關僅EVENT_ID 我做到了,但沒有什麼變化 @PrimaryKeyJoinColumn(NAME =「EVENT_ID」) – depa

+0

我已經更新了我的答案只是使用@JoinColumn (name =「EVENT_ID」) –

+0

感謝您的回覆,但沒有任何變化。我認爲這是一個休眠錯誤。檢查這個https://hibernate.atlassian.net/browse/HHH-5695 – depa