This is my first hibernate project. I"m building a simple user type web system. I have a Person.java class and a PaymentType.java class.
A Person object has fields like id, name, email, and PaymentType which is my own type or object, not a string or int. I want to be able to have one person have multiple payment types. I am no db expert so the if that it one-to-many , i don't know, i may be wrong. I am using a join table 'personpayment' . I cannot figure out how to do this. My main problem is the paymenttype field in the person object. I want to be able to get a set of paymenttypes in the person object for that field.
example:
Code:
public class Person
{
int person_id;
String name;
[b]Set paymentTypes;[/b]
}
what am i doing wrong?? I get mapping exception: An association from the table person payment refers to an unmapped class: java.util.Set
Hibernate version: 3
Mapping documents:<-------------------
this is for Person.java--------------------->
Code:
<hibernate-mapping package="packageName">
<class name="Person">
<id name="person_id" column="person_id">
<generator class="native"/>
</id>
<join table="personpayment" optional="true">
<key column="person_id" unique="false"/>
<many-to-one name="paymentType" column="paymentType_id" not-null="true"/>
</join>
</class>
</hibernate-mapping>
<-------------------
this is for PaymentType.java------------->
Code:
<hibernate-mapping package="packageName">
<class name="packageName.PaymentType">
<id name="paymentType_id" column="paymentType_id">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
<----------
here is my table structures --------------------->
CREATE TABLE `paymenttype` (
`paymenttype_id` int(9) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`description` text,
PRIMARY KEY (`paymenttype_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC COMMENT='InnoDB free: 3072 kB';
/*Table structure for table `person` */
drop table if exists `person`;
CREATE TABLE `person` (
`person_id` int(9) NOT NULL auto_increment,
`fname` varchar(50) default NULL,
`lname` varchar(50) default NULL,
`email` varchar(50) default NULL,
`username` varchar(50) default NULL,
PRIMARY KEY (`person_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
/*Table structure for table `personpayment` */
drop table if exists `personpayment`;
CREATE TABLE `personpayment` (
`person_id` int(9) NOT NULL,
`paymentType_id` int(9) NOT NULL,
`startDate` datetime default NULL,
`expiration` datetime default NULL,
`status` tinyint(1) default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC COMMENT='InnoDB free: 3072 kB';
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:mySql 5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: