dimanche 29 mars 2015

Why does hibernate entity class leading to bad value for int Exception?

First of all let me make my scenario clear I am using hibernate 4.3 ,Postgresql 9.3 with spring MVC ,and I have reverse engineered classes using JBOSS tool.


Every time I select the data using HQL or session.get() I am getting (SQL queries are working fine) Caused by : org.postgresql.util.PSQLException: Bad value for type int : demoemailaddr@gmail.com


my first entity class Applicant.java,



@Entity
@Table(name = "applicant", schema = "public", uniqueConstraints = { @UniqueConstraint(columnNames = "user_id"), @UniqueConstraint(columnNames = "email"), @UniqueConstraint(columnNames = "registration_id") })
public class Applicant implements java.io.Serializable
{
@Id
@Column(name = "application_id", unique = true, nullable = false, length = 7)
private String applicationId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "email", unique = true, nullable = false)
private Users usersByEmail;

// setters and getters
}


and Users class which has @ManytOne relationship with above class.



@Entity
@Table(name = "users", schema = "public", uniqueConstraints = { @UniqueConstraint(columnNames = "email"), @UniqueConstraint(columnNames = "application_id") })
public class Users implements java.io.Serializable
{
@Id
@Column(name = "user_id", unique = true, nullable = false)
private int userId;

@Column(name = "email", unique = true, nullable = false, length = 100)
private String email;

}


Now check the schema structure



CREATE TABLE users
(
email character varying(100) NOT NULL,
user_id integer NOT NULL,
CONSTRAINT users_pk PRIMARY KEY (user_id),
CONSTRAINT unique_email UNIQUE (email)
)

CREATE TABLE applicant
(
application_id character(7) NOT NULL,
email character varying(100) NOT NULL,
CONSTRAINT users_email_fk FOREIGN KEY (email)
REFERENCES users (email) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT unique_applicant_email UNIQUE (email)
)

Aucun commentaire:

Enregistrer un commentaire