-->
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.  [ 7 posts ] 
Author Message
 Post subject: PropertyNotFoundExeception:Could not find a getter for null
PostPosted: Mon Sep 22, 2003 11:20 pm 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
Thanks in advance for the help..

Running the latest Hibernate version (2.1 beta) and I'm receiving the following error when attempting to create a Configuration

&*&*&*&*&*&*&*&
SEVERE: Could not compile the mapping document
net.sf.hibernate.PropertyNotFoundException: Could not find a getter for null in class mtmdemo.Permission
at net.sf.hibernate.util.ReflectHelper.getGetter(ReflectHelper.java:206)
*&*&*&*&*&*&*&*&

Here is the code: - if I just run the statement w/ the User class it works just fine.
Transaction tx = null;

Configuration ds = new Configuration().addClass(Permission.class)
.addClass(User.class);

Here is the code for the Permission and User Classes

/**
* Class that represents a permission.
*
*/
public class Permission {

private double id;
private String name;
private Set users = new HashSet();


public Permission() {
super();
// TODO Auto-generated constructor stub
}


/**
* ID accessors
*/
public double getId() {
return id;
}
public void setId(double iD) {
id = iD;
}

/**
* Name accessors
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

/**
* User accessors
*/
public Set getUsers() {
return users;
}
public void setUsers(Set users) {
this.users = users;
}
public void addUser(User user){
users.add(user);
}
public void removeUser(User user){
users.remove(user);
}

}


/**
* Class that represents a user.
*
*/
public class User {

private double id;
private String name;
private Set permissions = new HashSet();

public User() {
super();
// TODO Auto-generated constructor stub
}

/**
* ID accessors
*/
public double getId() {
return id;
}
public void setId(double iD) {
id = iD;
}

/**
* Name accessors
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

/**
* Permission accessors
*/
public Set getPermissions() {
return permissions;
}
public void setPermissions(Set permissions) {
this.permissions = permissions;
}
public void addPermission(Permission permission){
permissions.add(permission);
}
public void removePermission(Permission permission){
permissions.remove(permission);
}

}

*** And here are the mappings for Permission and User
*** Permission Mapping
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">

<hibernate-mapping>
<class name="mtmdemo.Permission" table="permissions">
<id name="id" type="long" column="permissionid">
<generator class="native"/>
</id>
<property name="name" column="permissionname" not-null="true"/>
<set role="users" table="userpermissions" readonly="true" lazy="true">
<key column="permissionid"/>
<many-to-many class="mtmdemo.User" column="userid"/>
</set>
</class>
</hibernate-mapping>

*** User Mapping
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">

<hibernate-mapping>
<class name="mtmdemo.User" table="users">
<id name="id" column="userid" not-null="true">
<generator class="native"/>
</id>
<property name="name" column="username" unique="false" not-null="true" />
<set name="permissions" table="userpermissions" lazy="true">
<key column="userid"/>
<many-to-many class="mtmdemo.Permission" column="permissionid"/>
</set>
</class>
</hibernate-mapping>


net.sf.hibernate.MappingException: Problem trying to set property type by reflection: Could not find a getter for null in class mtmdemo.Permission


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 7:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You are mixing 1X and 2X mapping syntax. Change the Permission mapping for the user set to:
Code:
<set name="users" table="userpermissions" inverse="true" lazy="true">
    <key column="permissionid"/>
    <many-to-many class="mtmdemo.User" column="userid"/>
</set>


Note:
role -> name
readonly -> inverse

You had it correct on the User's set mapping...


Top
 Profile  
 
 Post subject: not quite yet
PostPosted: Tue Sep 23, 2003 8:46 am 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
Still does not work.. now I get :

org.xml.sax.SAXParseException: Attribute "inverse" is not declared for element "set".
at org.apache.crimson.parser.Parser2.error(Parser2.java:3317)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1558)
.
.
.
org.xml.sax.SAXParseException: Attribute value for "role" is #REQUIRED.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3317)


I tried putting role back and removing inverse to no avail..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 9:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
In your mapping see how you have:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">

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

And change role->name; readonly->inverse


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 9:19 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
For the SAXParseException, try using <bag> instead of <set>. I found these much easier to work with.

One of mine is like this:

<bag name="Child" cascade="all" inverse="true" lazy ="false">
<key column="ParentID" />
<one-to-many class="my.package.impl.ChildImpl" />
</bag>

----------------------------------------------------------------------------
I have my lazy set to false, as my database calls can take a while, so best to grab in one call, as I generally always process the entire structure.

-G


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 9:21 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
And oh yes, do as Steve says...about the mapping bit. :)

-G


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 11:41 am 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
That fixed it!..
I appreciate the help! Great Forum!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.