Hi,
my program has customer and login tables having one-to-one relationship using many-to-one and unique
I am getting error while running the code
loginmanager=(LoginManager)ctx.getBean("loginManager");
Hibernate mapping
<hibernate-mapping>
<class name="fl_java.com.portfolio.model.Customers" table="CUSTOMERS" schema="">
<id name="customerid" type="java.lang.Long">
<column name="CUSTOMERID" length="10" />
<generator class="increment" />
</id>
<property name="title" type="string">
<column name="TITLE" length="4" not-null="true" />
</property>
<property name="firstname" type="string">
<column name="FIRSTNAME" length="30" not-null="true" />
</property>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="fl_java.com.portfolio.model.Login" table="LOGIN" schema="">
<id name="loginid" type="string">
<column name="LOGINID" length="20" />
<generator class="assigned" />
</id>
<many-to-one name="customers" class="fl_java.com.portfolio.model.Customers" fetch="select">
<column name="CUSTID" length="10" not-null="true" unique="true"/>
</many-to-one>
<property name="password" type="string">
<column name="PASSWORD" length="20" not-null="true" />
</property>
</class>
</hibernate-mapping>
Class
public class Customers implements java.io.Serializable {
private Long customerid;
private String firstname;
/** default constructor */
public Customers() {
}
public Customers(Long customerid, String firstname)
{
this.customerid = customerid;
this.firstname = firstname;
}
// Property accessors
public Long getCustomerid() {
return this.customerid;
}
public void setCustomerid(Long customerid) {
this.customerid = customerid;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
}
public class Login implements java.io.Serializable {
private String loginid;
private Customers customers;
private String password;
public Login(String loginid, Customers customers, String password) {
this.loginid = loginid;
this.customers = customers;
this.password = password;
}
public String getLoginid() {
return this.loginid;
}
public void setLoginid(String loginid) {
this.loginid = loginid;
}
public Customers getCustomers() {
return this.customers;
}
public void setCustomers(Customers customers) {
this.customers = customers;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
Class in Spring
public interface LoginDAO
{
public List getLogins();
public Login getLogin(String loginId);
public Login getLogin(Long customerId);
public void saveLogin(Login login);
public void removeLogin(String loginId);
public Boolean isExistsCustomer(Long custId);
public Boolean isExistsLogin(String loginId);
public Boolean isEnabled(String loginId);
public Boolean EnableLogin(String loginId);
public Boolean DisableLogin(String loginId);
}
public class LoginDAOHibernate extends HibernateDaoSupport implements LoginDAO
{
public List getLogins() {
return getHibernateTemplate().find("from Login");
}
public Login getLogin(String loginId) {
Login login = (Login) getHibernateTemplate().get(Login.class, loginId);
if (login == null) {
throw new ObjectRetrievalFailureException(Login.class, loginId);
}
return login;
}
.............................
}
public class LoginManagerI
{
private LoginDAO dao;
public void setLoginDAO(LoginDAO dao)
{
this.dao = dao;
}
public List getLogins()
{
List logins=dao.getLogins();
if (logins == null)
{
log.warn("No Logins Found in login database ");
}
return logins;
}
..........................
}
Entry in application-context.xml is
<bean id="loginDAO" class="fl_java.com.portfolio.dao.LoginDAOHibernate">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="txProxyTemplate" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="enable*">PROPAGATION_REQUIRED</prop>
<prop key="disable*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="customersManager" parent="txProxyTemplate">
<property name="target">
<bean class="fl_java.com.portfolio.service.CustomersManagerI">
<property name="customersDAO">
<ref local="customersDAO"/>
</property>
</bean>
</property>
</bean>
<bean id="loginManager" parent="txProxyTemplate">
<property name="target">
<bean class="fl_java.com.portfolio.service.LoginManagerI">
<property name="loginDAO">
<ref local="loginDAO"/>
</property>
</bean>
</property>
</bean>
Error
1) testSaveSingle(fl_java.com.portfolio.test.service.LoginManagerTest)java.lang.ClassCastException: fl_java.com.portfolio.service.LoginManagerI$$EnhancerByCGLIB$$a8c9a63a
at fl_java.com.portfolio.test.service.LoginManagerTest.setUp(LoginManagerTest.java:41)
at fl_java.com.portfolio.test.service.LoginManagerTest.main(LoginManagerTest.java:30)
|