簡體   English   中英

IllegalArgumentException,屬性的getter方法,避免冗余數據

[英]IllegalArgumentException, getter method of property, avoiding redundant data

我正在嘗試將新行程添加到數據庫中。 它們之間存在多對一的關系,因此可以將一個位置分配到多個位置。 地點已正確添加,但是在添加行程時會出現此異常...我知道有很多類似的主題,但是沒有一個主題幫助我解決了這個問題。

ERROR: HHH000122: IllegalArgumentException in class: pl.th.java.biuro.hibernate.Place, getter method of property: idPlace
Exception found while adding new trip: IllegalArgumentException occurred calling getter of pl.th.java.biuro.hibernate.Place.idPlace
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of pl.th.java.biuro.hibernate.Place.idPlace
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:192)

休眠行程映射:

<hibernate-mapping>
<class name="pl.th.java.biuro.hibernate.Trip" table="Trip">
    <id column="idTrip" name="idTrip" type="int"/>
    <property column="date" name="date" type="date"/>
    <property column="cost" name="cost" type="int"/>
    <property column="profit" name="profit" type="int"/>
    <property column="organisator" name="organisator" type="string"/>
    <property column="period" name="period" type="int"/>
    <property column="food" name="food" type="string"/>
    <property column="transport" name="transport" type="string"/>
    <property column="persons" name="persons" type="int"/>
    <property column="kidsAmount" name="kidsAmount" type="int"/>
    <property column="idHotel" name="idHotel" type="int"/>
    <many-to-one name="idPlace" column="idPlace" class="pl.th.java.biuro.hibernate.Place" not-null="true" />
</class>

休眠位置映射:

<hibernate-mapping>
<class name="pl.th.java.biuro.hibernate.Place" table="Place">
    <id column="idPlace" name="idPlace" type="int">
        <generator class="native"/>
    </id>
    <property column="country" name="country" type="string"/>
    <property column="city" name="city" type="string"/>
    <property column="island" name="island" type="string"/>
    <property column="information" name="information" type="string"/>
</class>

行程類別:

public class Trip {

private int idTrip;
private int idPlace;
private int idHotel;
private Date date;
private int cost;
private int profit;
private String organisator;
private int period;
private String food;
private String transport;
private int persons;
private int kidsAmount;

private String ownerName;
private String ownerLastName;

private Place place;

public Trip() {

}

public Trip(int idTrip, Date date, int cost, int profit, String organisator, int period, String food, String transport, int persons, int kidsAmount) {
    this.idTrip = idTrip;
    this.date = date;
    this.cost = cost;
    this.profit = profit;
    this.organisator = organisator;
    this.period = period;
    this.food = food;
    this.transport = transport;
    this.persons = persons;
    this.kidsAmount = kidsAmount;
}

public Trip(int idTrip, Date date, int cost, int profit, String organisator, int period, String food, String transport, int persons, int kidsAmount, String ownerName, String ownerLastName, Place place) {
    this.idTrip = idTrip;
    this.date = date;
    this.cost = cost;
    this.profit = profit;
    this.organisator = organisator;
    this.period = period;
    this.food = food;
    this.transport = transport;
    this.persons = persons;
    this.kidsAmount = kidsAmount;
    this.ownerName = ownerName;
    this.ownerLastName = ownerLastName;
    this.place = place;
}

/**
 * @return the idTrip
 */
public int getIdTrip() {
    return idTrip;
}

/**
 * @param idTrip the idTrip to set
 */
public void setIdTrip(int idTrip) {
    this.idTrip = idTrip;
}

    /**
 * @return the place
 */
public Place getPlace() {
    return place;
}

/**
 * @param place the place to set
 */
public void setPlace(Place place) {
    this.place = place;
}
And other get/set methods...

地方課程:

public class Place {


private int idPlace;
private String country;
private String city;
private String island;
private String information;

public Place() {

}

public Place(String country, String city, String island, String information) {
    this.country = country;
    this.city = city;
    this.island = island;
    this.information = information;
}

/**
 * @return the idPlace
 */
public int getIdPlace() {
    return idPlace;
}

/**
 * @param idPlace the idPlace to set
 */
public void setIdPlace(int idPlace) {
    this.idPlace = idPlace;
}

EDIT1添加適當的實體現在為我工作,但我想知道有沒有什么辦法來避免冗余數據? 例如,我添加了一個行程,並與此行連接的部位X。 當我添加另一行,但在這同一個地方 - X,這個地方再次添加到我的數據庫。 如何避免這種行為?

ERROR: HHH000122: IllegalArgumentException in class: pl.th.java.biuro.hibernate.Place, getter method of property: idPlace

我認為您在插入操作中得到了這個。 前面的意思是,您正在向idPlace列插入非法參數。 你用many-to-onepl.th.java.biuro.hibernate.Place並插入一個intpl.th.java.biuro.hibernate.Place 您必須將idPlace類型從int更改為pl.th.java.biuro.hibernate.Place

我希望這能幫到您。

您應該修改int idPlace int到對象的旅程pl.th.java.biuro.hibernate.Place

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM