2015-06-23 156 views
0

我的Hibernate映射給出了一個錯誤:Hibernate和拋出:IllegalArgumentException

Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of opdracht5.Category.id 

我似乎無法找出它發生......有人可以幫我嗎?

我Category.hbm.xml:

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping> 
    <class name="opdracht5.Category" table="Category"> 
    <id name="id"> 
    <generator class="increment"></generator> 
    </id> 
    <set name="advertenties" cascade="all"> 
     <key column="CATEGORY_ID"></key> 
     <one-to-many class="opdracht5.Category"/> 
    </set>  
    <property name="naam" type="string"></property> 

</class> 

</hibernate-mapping> 

我Category類。

public class Category { 
private String naam; 
private long id; 
private Set<Advertentie> advertenties; 

public Category() {} 
public Category(String naam){ 
    this.naam = naam; 
} 

public void setNaam(String naam){ 
    this.naam = naam; 
} 
public void setAdvertenties(Set<Advertentie> advertenties){ 
    this.advertenties = advertenties; 
} 
public Set<Advertentie> getAdvertenties(){ 
    return advertenties; 
} 

public String getNaam(){ 
    return naam; 
} 
public void setId(long id){ 
    this.id = id; 
} 

public long getId(){ 
    return id; 
} 
} 

Advertentie.hbm.xml

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping> 
    <class name="opdracht5.Advertentie" table="Advertentie"> 
    <id name="id"> 
<generator class="native"></generator> 
</id> 

<property name="naam"></property> 
<property name="beschrijving"></property> 
<property name="startPrijs"></property> 
<property name="actief"></property> 
<property name="StartDate"></property> 
<many-to-one name="categoryNaam" class="opdracht5.Category" 
     column="CATEGORY_ID" not-null="true"/> 
    </class> 

</hibernate-mapping> 

Advertentie.java

package opdracht5; 
import java.util.*; 
public class Advertentie { 
private String naam; 
private String beschrijving; 
private int startPrijs; 
private Boolean actief; 
private Date StartDate; 
private Category categoryNaam; 
private long id; 
public Advertentie() { 
    // TODO Auto-generated constructor stub 
} 

public Advertentie(String naam, String beschrijving, int startPrijs, Boolean actief, Date StartDate, Category categoryNaam){ 
    this.naam = naam; 
    this.beschrijving = beschrijving; 
    this.startPrijs = startPrijs; 
    this.actief = actief; 
    this.StartDate = StartDate; 
    this.categoryNaam = categoryNaam; 
} 
public Category getCategoryNaam(){ 
    return categoryNaam; 
} 
public void setCategoryNaam(Category categoryNaam){ 
    this.categoryNaam= categoryNaam; 
} 
public String getNaam(){ 
    return naam; 
} 
public String getBeschrijving(){ 
    return beschrijving; 
} 
public int getStartPrijs(){ 
    return startPrijs; 
} 
public Boolean getActief(){ 
    return actief; 
} 
public Date getStartDate(){ 
    return StartDate; 
} 
public long getId(){ 
    return id; 
} 
public void setId(long id){ 
    this.id = id; 
} 
public void setNaam(String naam){ 
    this.naam = naam; 
} 
public void setBeschrijving(String beschrijving){ 
    this.beschrijving = beschrijving; 
} 
public void setStartPrijs(int startPrijs){ 
    this.startPrijs = startPrijs; 
} 
public void setActief(Boolean actief){ 
    this.actief = actief; 
} 
public void setStartDate(Date StartDate){ 
    this.StartDate = StartDate; 
} 
} 

最後幾行的log4j:

DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated  identifier: 1, using strategy: org.hibernate.id.IncrementGenerator 
**strong text**10022 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - saving  [opdracht5.Category#1] 
**strong text**10025 [main] DEBUG org.hibernate.engine.Cascade - processing cascade ACTION_SAVE_UPDATE for: opdracht5.Category 
**strong text**10025 [main] DEBUG org.hibernate.engine.Cascade - done processing cascade ACTION_SAVE_UPDATE for: opdracht5.Category 
**strong text**10033 [main] DEBUG org.hibernate.event.def.WrapVisitor  - Wrapped collection in role: opdracht5.Category.advertenties 
**strong text**10037 [main] DEBUG org.hibernate.engine.Cascade - processing cascade ACTION_SAVE_UPDATE for: opdracht5.Category 
**strong text**10037 [main] DEBUG org.hibernate.engine.Cascade - cascade ACTION_SAVE_UPDATE for collection: opdracht5.Category.advertenties 
**strong text**10037 [main] DEBUG org.hibernate.engine.CascadingAction - cascading to saveOrUpdate: opdracht5.Category 
**strong text**10038 [main] ERROR org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in  class: opdracht5.Category, getter method of property: id 

如何解決這一持續的錯誤? 我一直在盯着我的屏幕幾個小時。

+0

的代碼是什麼造成這種異常? – mhlz

+0

@mhlz類別中的映射(添加最後~10 log4j行) –

回答

相關問題