hello everyone
I'm working on a project that utilizes Hibernate, Spring, Flex(Flex technology involved in the presentation layer) and thanks to BlazeDS.
I have made a simple example with only one table and i implement (CRUD) in this table thanks to hibernate , and it works. But I made another example with many tables and associations ( many-to-one, one-to-many,..) and i create my services . In the blazeds when i try to retrieve data from class (like employees) thanks to Testoperations an error displays during the test
here are my classesCode:InvocationTargetException:There was an error while invoking the operation. Check your server settings and try invoking the operation again. Reason: Server error failed to lazily initialize a collection of role: com.proxym.grh.domain.Employees.trainees, no session or session was closed null
Employees
web.xmlCode:@Entity @Table(name = "employees", catalog = "proxym_flex_spring", uniqueConstraints = @UniqueConstraint(columnNames = "username")) public class Employees { public Integer idemployees; public Employees employees; public String firstame,lastname,mail; ....... public Set<Adressemployees> adressemployeeses = new HashSet<Adressemployees>( 0); public Set<Vacation> vacations = new HashSet<Vacation>(0); public Set<Trainee> trainees = new HashSet<Trainee>(0); public Set<Phoneemployees> phoneemployeeses = new HashSet<Phoneemployees>( 0); public Set<Rules> ruleses = new HashSet<Rules>(0); public Set<Salary> salaries = new HashSet<Salary>(0); public Set<Cv> cvs = new HashSet<Cv>(0); public Set<Employees> employeeses = new HashSet<Employees>(0); public Employees() { } public Employees(String firstame, String lastname, String mail, String functions) { this.firstame = firstame; this.lastname = lastname; this.mail = mail; this.functions = functions; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "idemployees", unique = true, nullable = false) public Integer getIdemployees() { return this.idemployees; } public void setIdemployees(Integer idemployees) { this.idemployees = idemployees; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "manager_id") public Employees getEmployees() { return this.employees; } public void setEmployees(Employees employees) { this.employees = employees; } //setter and getter for simple variables (firstname, lastname, mail,...) @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Adressemployees> getAdressemployeeses() { return this.adressemployeeses; } public void setAdressemployeeses(Set<Adressemployees> adressemployeeses) { this.adressemployeeses = adressemployeeses; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Vacation> getVacations() { return this.vacations; } public void setVacations(Set<Vacation> vacations) { this.vacations = vacations; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Trainee> getTrainees() { return this.trainees; } public void setTrainees(Set<Trainee> trainees) { this.trainees = trainees; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Phoneemployees> getPhoneemployeeses() { return this.phoneemployeeses; } public void setPhoneemployeeses(Set<Phoneemployees> phoneemployeeses) { this.phoneemployeeses = phoneemployeeses; } @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "employees_rules", catalog = "proxym_flex_spring", joinColumns = { @JoinColumn(name = "employees_idemployees", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "rules_idrules", nullable = false, updatable = false) }) public Set<Rules> getRuleses() { return this.ruleses; } public void setRuleses(Set<Rules> ruleses) { this.ruleses = ruleses; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Salary> getSalaries() { return this.salaries; } public void setSalaries(Set<Salary> salaries) { this.salaries = salaries; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Cv> getCvs() { return this.cvs; } public void setCvs(Set<Cv> cvs) { this.cvs = cvs; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Employees> getEmployeeses() { return this.employeeses; } public void setEmployeeses(Set<Employees> employeeses) { this.employeeses = employeeses; } }
dispatcherServletCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Spring and Flex</display-name> <description>Spring and Flex</description> <!-- Http Flex Session attribute and binding listener support --> <listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>RDSDispatchServlet</servlet-name> <display-name>RDSDispatchServlet</display-name> <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class> <init-param> <param-name>messageBrokerId</param-name> <param-value>_messageBroker</param-value> </init-param> <init-param> <param-name>useAppserverSecurity</param-name> <param-value>false</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> <servlet-mapping id="RDS_DISPATCH_MAPPING"> <servlet-name>RDSDispatchServlet</servlet-name> <url-pattern>/CFIDE/main/ide.cfm</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping> </web-app>
and my servicesCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <flex:message-broker> <flex:remoting-service default-channels="my-amf" /> </flex:message-broker> <context:annotation-config /> <context:component-scan base-package="com.proxym.grh" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/proxym_flex_spring" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.proxym.grh" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.hbm2ddl.auto">validate</prop> </props> </property> </bean> <bean id="myemployees" class="com.proxymit.grh.dao.impl.EmployeesDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> </beans>
Any one have an idea please ??Code:...... @RemotingInclude public List<Employees> findallEmploye() { // TODO Auto-generated method stub return template.find("from Employees"); }


Reply With Quote