Hibernate:Unknown mappedBy in :,引用的属性unknown:

时间:2015-11-04 16:29:38

标签: java hibernate annotations oracle10g mapping

我正在尝试映射我的表以使用Hibernate,但是当我启动测试时出现了这个错误。

    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自动生成的

3 个答案:

答案 0 :(得分:1)

好的!我认为这是一个Hibernate BUG。我发现了这个

https://hibernate.atlassian.net/browse/HHH-5695

答案 1 :(得分: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;
}
.....

}

答案 2 :(得分:0)

请在class TEventsDetails的以下行中定义列的名称,因为您已定义TEventsDetails表的哪些列与TEvents表相关联。

@JoinColumn(name = "EVENT_ID")