-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: PropertyNotFoundException: Could not find a getter for null
PostPosted: Wed Nov 05, 2003 11:30 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
I am using hibernate-2.0.3 with the MEagle's Xdoclet tutorial: http://www.meagle.com:8080/hibernate.jsp. I started with the association: User 1 ---- * Contact . I was able to generate the mappings and export the schema to mysql4.0.16. But when I tried to build the SessionFactory I got the following exception:
net.sf.hibernate.PropertyNotFoundException: Could not find a getter for null in class dbdemo.User

Below are the persistent objects, generated mappings, code snippet from Test class, and the exception thrown:

package dbdemo;

import java.util.Date;
import java.util.Set;

/**
* @hibernate.class table="Users"
*
* @author MEagle
*
* Represents a User
*/
public class User {

private String userID;
private String userName;
private String password;
private String emailAddress;
private Date lastLogon;
private Set contacts;

public User(){
}

/**
* @hibernate.property column="EmailAddress" type="string"
* @return
*/
public String getEmailAddress() {
return emailAddress;
}

/**
* @hibernate.property column="LastLogon" type="date"
* @return
*/
public Date getLastLogon() {
return lastLogon;
}

/**
* @hibernate.property column="Password" type="string"
* @return
*/
public String getPassword() {
return password;
}

/**
* @hibernate.id generator-class="native" type="string"
* column="LogonID"
* @return
*/
public String getUserID() {
return userID;
}

/**
* @hibernate.property column="Name" type="string"
* @return
*/
public String getUserName() {
return userName;
}

/**
* @param string
*/
public void setEmailAddress(String string) {
emailAddress = string;
}

/**
* @param string
*/
public void setLastLogon(Date date) {
lastLogon = date;
}

/**
* @param string
*/
public void setPassword(String string) {
password = string;
}

/**
* @param string
*/
public void setUserID(String string) {
userID = string;
}

/**
* @param string
*/
public void setUserName(String string) {
userName = string;
}

/**
* @hibernate.set role="contacts" table="Contacts"
* cascade="all" readonly="true"
* @hibernate.collection-key column="User_ID"
* @hibernate.collection-one-to-many class="dbdemo.Contact"
* @return
*/
public Set getContacts() {
return contacts;
}

/**
* @param set
*/
public void setContacts(Set set) {
contacts = set;
}
}


package dbdemo;

/**
* @author MEagle
* @hibernate.class table="Contacts"
* Represents a contact.
*/
public class Contact {

private long contactId;
private String name;
private String email;

// foreign key field for the parent
private String userId;

// relationship field
private User user;

public Contact(){
}

/**
* @hibernate.id generator-class="native" type="integer" column="ID"
*
* @return long
*/
public long getContactId() {
// use this if you are using a dialect that does not support sequences
// @hibernate.id generator-class="native" type="integer" column="ID"

// Use this if you are using a dialect that supports sequences
// @hibernate.id generator-class="sequence" type="long" column="ID"
// @hibernate.generator-param name="sequence" value="seq"
return contactId;
}

/**
* @hibernate.property column="EmailAddress" type="string"
* @return String
*/
public String getEmail() {
return email;
}

/**
* @hibernate.property column="Name" type="string"
* @return String
*/
public String getName() {
return name;
}

/**
* @param long
*/
public void setContactId(long l) {
contactId = l;
}

/**
* @param string
*/
public void setEmail(String string) {
email = string;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}



/**
* @return String
*/
public String getUserId() {
return userId;
}

/**
* @param string
*/
public void setUserId(String string) {
userId = string;
}

/**
* @hibernate.many-to-one column="User_ID" class="dbdemo.User"
* @return User
*/
public User getUser() {
return user;
}

/**
* @param user
*/
public void setUser(User user) {
this.user = user;
}

}


<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">

<hibernate-mapping>
<class
name="dbdemo.User"
table="Users"
>

<id
name="userID"
column="LogonID"
type="string"
unsaved-value="any"
>
<generator class="native">
</generator>
</id>

<property
name="emailAddress"
type="string"
column="EmailAddress"
/>

<property
name="lastLogon"
type="date"
column="LastLogon"
/>

<property
name="password"
type="string"
column="Password"
/>

<property
name="userName"
type="string"
column="Name"
/>

<set
role="contacts"
table="Contacts"
lazy="false"
readonly="true"
cascade="all"
sort="unsorted"
>

<key
column="User_ID"
/>

<one-to-many
class="dbdemo.Contact"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-User.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">

<hibernate-mapping>
<class
name="dbdemo.Contact"
table="Contacts"
>

<id
name="contactId"
column="ID"
type="integer"
unsaved-value="any"
>
<generator class="native">
</generator>
</id>

<property
name="email"
type="string"
column="EmailAddress"
/>

<property
name="name"
type="string"
column="Name"
/>

<many-to-one
name="user"
class="dbdemo.User"
cascade="none"
outer-join="auto"
column="User_ID"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Contact.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


.......
Configuration configuration = new Configuration();
Properties properties = new Properties();
properties.load(Test.class.getClassLoad().getResourceAsStream("test/hibernate(mysql).properties"));
configuration.setProperties(properties);

configuration.addClass(dbdemo.User.class);
configuration.addClass(dbdemo.Contact.class);

SessionFactory sessionFactory = configuration.buildSessionFactory(); // Line 26
......


Nov 5, 2003 10:06:07 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.3
Nov 5, 2003 10:06:08 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Nov 5, 2003 10:06:08 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Nov 5, 2003 10:06:08 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
Nov 5, 2003 10:06:08 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: dbdemo/User.hbm.xml
Nov 5, 2003 10:06:08 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: dbdemo.User -> Users
Nov 5, 2003 10:06:09 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: dbdemo/Contact.hbm.xml
Nov 5, 2003 10:06:09 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: dbdemo.Contact -> Contacts
Nov 5, 2003 10:06:09 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Nov 5, 2003 10:06:09 PM net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: dbdemo.User.null -> Contacts
Nov 5, 2003 10:06:09 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Nov 5, 2003 10:06:09 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 5, 2003 10:06:09 PM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
Nov 5, 2003 10:06:09 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 10
Nov 5, 2003 10:06:09 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernate
Nov 5, 2003 10:06:09 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {}
Nov 5, 2003 10:06:09 PM net.sf.hibernate.ps.PreparedStatementCache <init>
INFO: prepared statement cache size: 25
Nov 5, 2003 10:06:09 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use outer join fetching: true
Nov 5, 2003 10:06:10 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use scrollable result sets: true
Nov 5, 2003 10:06:10 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: echoing all SQL to stdout
net.sf.hibernate.PropertyNotFoundException: Could not find a getter for null in class dbdemo.User
at net.sf.hibernate.util.ReflectHelper.getGetter(ReflectHelper.java:206)
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:571)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:665)
at net.sf.hibernate.persister.PersisterFactory.create(PersisterFactory.java:29)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:207)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at test.Test.main(Test.java:26)


Thank you very much.

Mota


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 7:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You're using a generator for Hibernate 1.x.

Code:
<set
role="contacts"
table="Contacts"
lazy="false"
readonly="true"
cascade="all"
sort="unsorted"
>


should be
Code:
<set
name="contacts"
table="Contacts"
lazy="false"
readonly="true"
cascade="all"
sort="unsorted"
>


And
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">

should be
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


Use a proper generator.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.