Re: [flexcoders] Flex + Java + Hibernate

2009-05-26 Thread foodyi
madhavaram123 写道:
> Hi All,
>
> I am facing a peculiar problem while saving the data. Below is the detailed 
> explanation what I am doing. I always get the problem as "a different object 
> with the same identifier value was already associated with the session"
>
> But the above error does not come when I try to save the same object from 
> java.
>
> Below is the Parent Class in java
> [code]
> import java.util.ArrayList;
> import java.util.HashSet;
> import java.util.List;
> import java.util.Set;
>
> /**
>  * Employee entity. @author MyEclipse Persistence Tools
>  */
>
> public class Employee implements java.io.Serializable {
>
>   private Integer employeeId;
>   private String name;
>   private List communicationTypes = new ArrayList();
>
> // getters and setters follows
> [/code]
>
> Below is the Parent class in Flex
> [code]
> package manageCustomList.employee
> {
>   import mx.collections.ArrayCollection;
>   
>   [Bindable]
>   [RemoteClass(alias="com.config.Employee")]
>   public class Employee
>   {
>   public function Employee()
>   {
>   }
>
>   public var employeeId:int;
>   
>   public var name:String;
>
>   public var communicationTypes:Array;
>   }
> }
> [/code]
>
> Below is the Child Class in java
> [code]
> public class CommunicationType extends Employee implements 
> java.io.Serializable {
>   private Integer comTypeId;
>   private Integer typeId;
>   private String typeName;
> // getters and setters follows
> }
> [/code]
>
> Below is the child Class in Flex
> [code]
> package manageCustomList.employee
> {
>   import mx.controls.List;
>   
>   [Bindable]
>   [RemoteClass(alias="com.config.CommunicationType")]
>   public class CommunicationType extends Employee
>   {
>   public function CommunicationType()
>   {
>   }
>
>   public var comTypeId:int;
>
>   public var typeId:int;
>
>   public var typeName:String;
>
>   }
> }
> [/code]
>
> Below is the method to save the object in the database
> [code]
> public static Employee create(Employee employee) throws DAOException
>   {
>   Session session = HibernateSessionFactory.getSession();
>   try
>   {
>   session.beginTransaction();
>   session.save(employee);
>   session.getTransaction().commit();
>   session.flush();
>   session.evict(employee);
>   }
>catch (HibernateException exp) {
>exp.printStackTrace();
>   } finally {
>   session.close();
>   }
>   return employee;
>   }
> [/code]
>
> Below is my mxml
> [code]
> private function save():void {
>   employee = new Employee();
>
>   employee.listId = Number(listId.text);
>   employee.name = empName.text;
>
>   var childList:Array = new Array();
>
>   for(var i:int=0;i   comType = new CommunicationType();
>   comType.typeId = checkList.selectedIndices[i];
>   comType.typeName = 
> checkList.dataProvider[checkList.selectedIndices[i]].label;
>   childList.push(comType);
>   }
>
>   employee.communicationTypes = childList;
>
>   emp.create(employee);
> }
> [/code]
>
> when I do the above i get the error as "a different object with the same 
> identifier value was already associated with the session"
>
> But when I try to save the employee from java as below. It gets saved without 
> any problem.
> [code]
> public static void main(String[] args) {
>   Employee emp = new Employee();
>   emp.setName("fresh from java only 2");
>
>   CommunicationType comType = new CommunicationType();
>   comType.setTypeId(1);
>   comType.setTypeName("typeName");
>
>   List comSet = new ArrayList();
>   comSet.add(comType);
>
>   emp.setCommunicationTypes(comSet);
>   create(emp);
> }[/code]
>
> below are my hbm files
> Employee.hbm.xml
> [code]
> 
> 
> 
> 
> 
> 
>   
> 
> 
> 
> 
> 
> 
>   
>   
>   
> 
> 
>
> [/code]
>
> CommunicationType.hbm.xml
> [code]
> 
>  schema="DISLIST">
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> [/code]
>
> Let me know if you any refernce of other things.
>
> Any help would be really helpful
>
> Thanks in advance
>
>
>   
hi, i suggest u to create a new java class which using BeanUtil copy 
properties from Employee class. you could crud the new class by hibernate.
do't persist the remote class to the database directly. good luck to u :)



[flexcoders] Flex + Java + Hibernate

2009-05-25 Thread madhavaram123
Hi All,

I am facing a peculiar problem while saving the data. Below is the detailed 
explanation what I am doing. I always get the problem as "a different object 
with the same identifier value was already associated with the session"

But the above error does not come when I try to save the same object from java.

Below is the Parent Class in java
[code]
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Employee entity. @author MyEclipse Persistence Tools
 */

public class Employee implements java.io.Serializable {

private Integer employeeId;
private String name;
private List communicationTypes = new ArrayList();

// getters and setters follows
[/code]

Below is the Parent class in Flex
[code]
package manageCustomList.employee
{
import mx.collections.ArrayCollection;

[Bindable]
[RemoteClass(alias="com.config.Employee")]
public class Employee
{
public function Employee()
{
}

public var employeeId:int;

public var name:String;

public var communicationTypes:Array;
}
}
[/code]

Below is the Child Class in java
[code]
public class CommunicationType extends Employee implements java.io.Serializable 
{
private Integer comTypeId;
private Integer typeId;
private String typeName;
// getters and setters follows
}
[/code]

Below is the child Class in Flex
[code]
package manageCustomList.employee
{
import mx.controls.List;

[Bindable]
[RemoteClass(alias="com.config.CommunicationType")]
public class CommunicationType extends Employee
{
public function CommunicationType()
{
}

public var comTypeId:int;

public var typeId:int;

public var typeName:String;

}
}
[/code]

Below is the method to save the object in the database
[code]
public static Employee create(Employee employee) throws DAOException
{
Session session = HibernateSessionFactory.getSession();
try
{
session.beginTransaction();
session.save(employee);
session.getTransaction().commit();
session.flush();
session.evict(employee);
}
 catch (HibernateException exp) {
 exp.printStackTrace();
} finally {
session.close();
}
return employee;
}
[/code]

Below is my mxml
[code]
private function save():void {
employee = new Employee();

employee.listId = Number(listId.text);
employee.name = empName.text;

var childList:Array = new Array();

for(var i:int=0;i


















[/code]

CommunicationType.hbm.xml
[code]














[/code]

Let me know if you any refernce of other things.

Any help would be really helpful

Thanks in advance