mysql中的hibernate关系

时间:2016-09-28 15:13:56

标签: java mysql hibernate

我正在尝试将pojo类映射到我的mysql数据库,但是当我想要获取用户时,我总是会收到错误:

java.sql.SQLSyntaxErrorException: Unknown column 'user0_.Report_id' in 'field list'

这就是数据库的样子:

database

这些是pojo课程:

顺序

package com.latinon.reportator.model;

import java.math.BigInteger;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author sistemas
 *
 */
@Entity
@Table(name="Order")
public class Order {



private Integer id;
private Date startDate;
private Date endDate;
private BigInteger imperssions;
private String zone;
private int monetization;
private String adUnit;
private String unit;
private String adFormat;
private Double totalAmount;
private Integer platform;
private Double value;
private String valueMesure;
private Set<Device> orderDevices = new HashSet<Device>(0);
private Set<Product> orderProducts = new HashSet<Product>(0);
private Set<Report> orderReport = new HashSet<Report>(0);
private Set<User> orderUsers = new HashSet<User>(0);



@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="Order_id")
public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

@Temporal(TemporalType.DATE)
@Column(name="Order_start_date", nullable=false)
public Date getStartDate() {
    return startDate;
}

public void setStartDate(Date startDate) {
    this.startDate = startDate;
}

@Temporal(TemporalType.DATE)
@Column(name="Order_end_date")
public Date getEndDate() {
    return endDate;
}

public void setEndDate(Date endDate) {
    this.endDate = endDate;
}

@Column(name="Order_impressions", nullable=false)
public BigInteger getImperssions() {
    return imperssions;
}

public void setImperssions(BigInteger imperssions) {
    this.imperssions = imperssions;
}

@Column(name="Order_zone")
public String getZone() {
    return zone;
}

public void setZone(String zone) {
    this.zone = zone;
}

@Column(name="Order_monetization",nullable=false)
public int getMonetization() {
    return monetization;
}

public void setMonetization(int monetization) {
    this.monetization = monetization;
}

@Column(name="Order_ad_unit")
public String getAdUnit() {
    return adUnit;
}

public void setAdUnit(String adUnit) {
    this.adUnit = adUnit;
}

@Column(name="Order_unit",nullable=false)
public String getUnit() {
    return unit;
}

public void setUnit(String unit) {
    this.unit = unit;
}

@Column(name="Order_ad_format", nullable=false)
public String getAdFormat() {
    return adFormat;
}

public void setAdFormat(String adFormat) {
    this.adFormat = adFormat;
}

@Column(name="Order_total_amount", nullable=false)
public Double getTotalAmount() {
    return totalAmount;
}

public void setTotalAmount(Double totalAmount) {
    this.totalAmount = totalAmount;
}

@Column(name="Order_platform", nullable=false)
public Integer getPlatform() {
    return platform;
}

public void setPlatform(Integer platform) {
    this.platform = platform;
}

@Column(name="Order_value", nullable=false)
public Double getValue() {
    return value;
}

public void setValue(Double value) {
    this.value = value;
}

@Column(name="Order_value_mesure",nullable=false)
public String getValueMesure() {
    return valueMesure;
}

public void setValueMesure(String valueMesure) {
    this.valueMesure = valueMesure;
}

@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name="Order_Device", joinColumns={
        @JoinColumn(name="Order_Device_Order_id")
})
public Set<Device> getOrderDevices() {
    return orderDevices;
}

public void setOrderDevices(Set<Device> orderDevices) {
    this.orderDevices = orderDevices;
}


@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name="Order_Product", joinColumns={
        @JoinColumn(name="Order_Product_Order_id")
})
public Set<Product> getOrderProducts() {
    return orderProducts;
}

public void setOrderProducts(Set<Product> orderProducts) {
    this.orderProducts = orderProducts;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "orderId")    
public Set<Report> getOrderReport() {
return orderReport;
}

public void setOrderReport(Set<Report> orderReport) {
    this.orderReport = orderReport;
}


@ManyToMany(fetch=FetchType.LAZY, mappedBy="userOrders")
public Set<User> getOrderUsers() {
    return orderUsers;
}

public void setOrderUsers(Set<User> orderUsers) {
    this.orderUsers = orderUsers;
}

@Override
public String toString() {
    return "Order [id=" + id + ", startDate=" + startDate + ", endDate=" + endDate + ", imperssions=" + imperssions
            + ", zone=" + zone + ", monetization=" + monetization + ", adUnit=" + adUnit + ", unit=" + unit
            + ", adFormat=" + adFormat + ", totalAmount=" + totalAmount + ", platform=" + platform + ", value="
            + value + ", valueMesure=" + valueMesure + "]";
}   
}

报告pojo:

    package com.latinon.reportator.model;

import java.math.BigInteger;
import java.util.Date;

import javax.persistence.*;

/**
* @author sistemas
*
*/
@Entity
@Table(name="User")
public class Report {

private Integer id;
private BigInteger impressions;
private Date date;
private Double grossRevenue;
private Double latinonRevenue;
private Double userRevenue;
private Double fillRate;
private BigInteger completion25;
private BigInteger completion50;
private BigInteger completion75;
private BigInteger completion100;
private BigInteger requests;
private String zone;
private Double cpm;
private Order orderId;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="Report_id")
public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

@Column(name="Report_impressions")
public BigInteger getImpressions() {
    return impressions;
}

public void setImpressions(BigInteger impressions) {
    this.impressions = impressions;
}

@Temporal(TemporalType.DATE)
@Column(name="Report_date")
public Date getDate() {
    return date;
}

public void setDate(Date date) {
    this.date = date;
}

@Column(name="Report_gross_revenue")
public Double getGrossRevenue() {
    return grossRevenue;
}

public void setGrossRevenue(Double grossRevenue) {
    this.grossRevenue = grossRevenue;
}

@Column(name="Report_latinon_revenue")
public Double getLatinonRevenue() {
    return latinonRevenue;
}

public void setLatinonRevenue(Double latinonRevenue) {
    this.latinonRevenue = latinonRevenue;
}

@Column(name="Report_user_revenue")
public Double getUserRevenue() {
    return userRevenue;
}

public void setUserRevenue(Double userRevenue) {
    this.userRevenue = userRevenue;
}

@Column(name="Report_fill_rate")
public Double getFillRate() {
    return fillRate;
}

public void setFillRate(Double fillRate) {
    this.fillRate = fillRate;
}

@Column(name="Report_completion_25")
public BigInteger getCompletion25() {
    return completion25;
}

public void setCompletion25(BigInteger completion25) {
    this.completion25 = completion25;
}

@Column(name="Report_completion_50")
public BigInteger getCompletion50() {
    return completion50;
}

public void setCompletion50(BigInteger completion50) {
    this.completion50 = completion50;
}

@Column(name="Report_completion_75")
public BigInteger getCompletion75() {
    return completion75;
}

public void setCompletion75(BigInteger completion75) {
    this.completion75 = completion75;
}

@Column(name="Report_completion_100")
public BigInteger getCompletion100() {
    return completion100;
}

public void setCompletion100(BigInteger completion100) {
    this.completion100 = completion100;
}

@Column(name="Report_request")
public BigInteger getRequests() {
    return requests;
}

public void setRequests(BigInteger requests) {
    this.requests = requests;
}

@Column(name="Report_zone")
public String getZone() {
    return zone;
}

public void setZone(String zone) {
    this.zone = zone;
}

@Column(name="Report_cpm")
public Double getCpm() {
    return cpm;
}

public void setCpm(Double cpm) {
    this.cpm = cpm;
}

@ManyToOne
@JoinColumn(name="Order_Order_id")
public Order getOrderId() {
    return orderId;
}

public void setOrderId(Order orderId) {
    this.orderId = orderId;
}

@Override
public String toString() {
    return "Report [id=" + id + ", impressions=" + impressions + ", date=" + date + ", grossRevenue=" + grossRevenue
            + ", latinonRevenue=" + latinonRevenue + ", userRevenue=" + userRevenue + ", fillRate=" + fillRate
            + ", completion25=" + completion25 + ", completion50=" + completion50 + ", completion75=" + completion75
            + ", completion100=" + completion100 + ", requests=" + requests + ", zone=" + zone + ", cpm=" + cpm
            + ", orderId=" + orderId + "]";
}

}

用户pojo:

package com.latinon.reportator.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name="User")
@Inheritance(strategy=InheritanceType.JOINED)
public class User {


private int id;
private String login;
private String password;
private String email;
private Set<Domain> userDomains = new HashSet<Domain>(0);
private Set<Order> userOrders = new HashSet<Order>(0);

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="User_id",nullable=false)
public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

@Column(name="User_login", length=45)
public String getLogin() {
    return login;
}

public void setLogin(String login) {
    this.login = login;
}

@Column(name="User_password", length=45)
public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

@Column(name="User_mail", length=45)
public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

@ManyToMany(fetch=FetchType.LAZY)
public Set<Domain> getUserDomains() {
    return userDomains;
}

public void setUserDomains(Set<Domain> userDomains) {
    this.userDomains = userDomains;
}


@ManyToMany(fetch=FetchType.LAZY)
public Set<Order> getUserOrders() {
    return userOrders;
}

public void setUserOrders(Set<Order> userOrders) {
    this.userOrders = userOrders;
}

@Override
public String toString() {
    return "User [id=" + id + ", login=" + login + ", password=" + password + ", email=" + email + "]";
}

}

1 个答案:

答案 0 :(得分:0)

您有报告课@Table(name="User")。这是一个错字吗?