Announcement Announcement Module
Collapse
No announcement yet.
Flex value object has null properties in java. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Flex value object has null properties in java.

    I have a simple service I have created using Spring-Flex 1.5. When I pass data from flex to java the value object is null on the java end. I have tested and debugged as much as I possibly could and I find not find a reason for this.

    I have tried to narrow the possibilities down as much as I could. So instead of doing anything with my data, I simply just return the passed in value object.

    I have verified that I am able to hit the service and the service does return data by creating the test(String dataString) method in my service. This method does return the correct result.

    This is the data that I am sending to java:
    (UserAccount)#0
    InstanceID = 1
    IsLoggedIn = false
    IsVisible = false
    UserID = NaN
    UserName = "user123"
    UserPass = "password"
    UserStatus = true
    UserTypeID = 1

    This is what I am receiving back:
    (UserAccount)#0
    InstanceID = NaN
    IsLoggedIn = false
    IsVisible = false
    UserID = NaN
    UserName = (null)
    UserPass = (null)
    UserStatus = false
    UserTypeID = NaN

    log4j log file:
    Code:
    723011 ["http-bio-8080"-exec-28] DEBUG com.rottmanj.services.user.UserAccountService  - com.rottmanj.domain.user.UserAccount@5994a1e9
    .
    Actionscript code:
    Code:
    	<fx:Script>
    		<![CDATA[
    			import mx.rpc.events.FaultEvent;
    			import mx.rpc.events.ResultEvent;
    			import mx.utils.ObjectUtil;		
    			
    			private function sendVO():void
    			{
    				var vo:UserAccount = new UserAccount();
    				vo.UserName = 'user123';
    				vo.UserPass = 'password';
    				vo.UserStatus = true;
    				vo.IsLoggedIn = false;
    				vo.IsVisible = false;
    				vo.UserTypeID = 1;
    				vo.InstanceID = 1;				
    				dBug.text = ObjectUtil.toString(vo);				
    				ro.save(vo);				
    			}
    			
    			private function resultHandler(event:ResultEvent):void
    			{
    				dBug.text = dBug.text + ObjectUtil.toString(event.result);
    			}
    			
    			private function faultHandler(event:FaultEvent):void
    			{
    				dBug.text = dBug.text + ObjectUtil.toString(event.fault);
    			}
    		]]>
    	</fx:Script>

    Actionscript VO:
    Code:
    [Bindable]
    	[RemoteClass(alias="com.rottmanj.domain.user.UserAccount")]
    	public class UserAccount
    	{ (setters/getters)...}
    Java Service:
    Code:
    @Service
    @RemotingDestination
    public class UserAccountService {
        
        private UserAccountDAO dao = null;
        private static Logger logger = Logger.getLogger(UserAccountService.class);
        
        @Autowired
        public void setDao(UserAccountDAO dao)
        {
            this.dao = dao;
        }
        
        @RemotingInclude
        public UserAccount save(UserAccount dataObject)
        {
        	logger.debug(dataObject.toString());    	
        	return dataObject;
        }
        
        @RemotingInclude
        public String test(String dataString)
        {
        	logger.debug(dataString.toString()); 
        	return "This is a Test for " + dataString;
        }
    }

  • #2
    Both java and actionscript VOs have matching variable names / accessors?

    Comment


    • #3
      amiladomingo, you were spot on. My AS properties did not match my java properties.

      However this lead me to a new error that stumps me. In my DAO I have this method:

      Code:
      	@Override
      	public UserAccount save(UserAccount obj) 
      	{
      		List<UserAccount> userList = template.findByExample(obj);
      		try {
      			if (!userList.isEmpty()) {
      				throw new Exception(
      						"A user with these credentials already exists. Please try again.");
      			} else {
      				template.saveOrUpdate(obj);
      			}
      		} catch (Exception e) {
      			logger.debug(e.toString());
      		}
      
      		return obj;
      	}
      When this method is called I get the following error:
      Code:
      org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.rottmanj.domain.user.UserAccount; nested exception is org.hibernate.MappingException: Unknown entity: com.rottmanj.domain.user.UserAccount
      I am calling my dao from my service that is exposed to flex. This is my current service:
      Code:
      @Service
      @RemotingDestination(channels = { "my-amf" })
      public class UserAccountService {
          
          private UserAccountDAO dao = null;
          private static Logger logger = Logger.getLogger(UserAccountService.class);
          
          @Autowired
          public void setDao(UserAccountDAO dao)
          {
              this.dao = dao;
          }
          
          @RemotingInclude
          public UserAccount save(UserAccount dataObject)
          {
          	return this.dao.save(dataObject);
          }
          
          @RemotingInclude
          public String test(String dataString)
          {
          	logger.debug(dataString.toString()); 
          	return "This is a Test for " + dataString;
          }
      }

      My Entity is annotated so there for it does not use mapping files. I have also ensured that I am using the correct import (import javax.persistence.Entity)

      This is my entity:
      Code:
      package com.rottmanj.domain.user;
      
      import java.util.HashSet;
      import java.util.Set;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import static javax.persistence.GenerationType.IDENTITY;
      import javax.persistence.Id;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;
      import javax.persistence.UniqueConstraint;
      
      @Entity
      @Table(name = "UserAccount", uniqueConstraints = @UniqueConstraint(columnNames = "UserName"))
      public class UserAccount implements java.io.Serializable {
      
      	private Integer userId;
      	private String userName;
      	private String userPass;
      	private short userTypeId;
      	private boolean userStatus;
      	private int instanceId;
      	private Boolean isLoggedIn;
      	private Boolean isVisible;
      	private Set userLicenses = new HashSet(0);
      	private Set userProfiles = new HashSet(0);
      	private Set userNotes = new HashSet(0);
      	private Set userAddresses = new HashSet(0);
      	private Set userPhones = new HashSet(0);
      	private Set userEmails = new HashSet(0);
      
      	public UserAccount() {
      	}
      
      	public UserAccount(String userName, String userPass, short userTypeId,
      			boolean userStatus, int instanceId) {
      		this.userName = userName;
      		this.userPass = userPass;
      		this.userTypeId = userTypeId;
      		this.userStatus = userStatus;
      		this.instanceId = instanceId;
      	}
      
      	public UserAccount(String userName, String userPass, short userTypeId,
      			boolean userStatus, int instanceId, Boolean isLoggedIn,
      			Boolean isVisible, Set userLicenses, Set userProfiles,
      			Set userNotes, Set userAddresses, Set userPhones, Set userEmails) {
      		this.userName = userName;
      		this.userPass = userPass;
      		this.userTypeId = userTypeId;
      		this.userStatus = userStatus;
      		this.instanceId = instanceId;
      		this.isLoggedIn = isLoggedIn;
      		this.isVisible = isVisible;
      		this.userLicenses = userLicenses;
      		this.userProfiles = userProfiles;
      		this.userNotes = userNotes;
      		this.userAddresses = userAddresses;
      		this.userPhones = userPhones;
      		this.userEmails = userEmails;
      	}
      
      	@Id
      	@GeneratedValue(strategy = IDENTITY)
      	@Column(name = "UserID", unique = true, nullable = false)
      	public Integer getUserId() {
      		return this.userId;
      	}
      
      	public void setUserId(Integer userId) {
      		this.userId = userId;
      	}
      
      	@Column(name = "UserName", unique = true, nullable = false, length = 50)
      	public String getUserName() {
      		return this.userName;
      	}
      
      	public void setUserName(String userName) {
      		this.userName = userName;
      	}
      
      	@Column(name = "UserPass", nullable = false, length = 32)
      	public String getUserPass() {
      		return this.userPass;
      	}
      
      	public void setUserPass(String userPass) {
      		this.userPass = userPass;
      	}
      
      	@Column(name = "UserTypeID", nullable = false)
      	public short getUserTypeId() {
      		return this.userTypeId;
      	}
      
      	public void setUserTypeId(short userTypeId) {
      		this.userTypeId = userTypeId;
      	}
      
      	@Column(name = "UserStatus", nullable = false)
      	public boolean isUserStatus() {
      		return this.userStatus;
      	}
      
      	public void setUserStatus(boolean userStatus) {
      		this.userStatus = userStatus;
      	}
      
      	@Column(name = "InstanceID", nullable = false)
      	public int getInstanceId() {
      		return this.instanceId;
      	}
      
      	public void setInstanceId(int instanceId) {
      		this.instanceId = instanceId;
      	}
      
      	@Column(name = "IsLoggedIn")
      	public Boolean getIsLoggedIn() {
      		return this.isLoggedIn;
      	}
      
      	public void setIsLoggedIn(Boolean isLoggedIn) {
      		this.isLoggedIn = isLoggedIn;
      	}
      
      	@Column(name = "IsVisible")
      	public Boolean getIsVisible() {
      		return this.isVisible;
      	}
      
      	public void setIsVisible(Boolean isVisible) {
      		this.isVisible = isVisible;
      	}
      
      	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
      	public Set getUserLicenses() {
      		return this.userLicenses;
      	}
      
      	public void setUserLicenses(Set userLicenses) {
      		this.userLicenses = userLicenses;
      	}
      
      	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
      	public Set getUserProfiles() {
      		return this.userProfiles;
      	}
      
      	public void setUserProfiles(Set userProfiles) {
      		this.userProfiles = userProfiles;
      	}
      
      	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
      	public Set getUserNotes() {
      		return this.userNotes;
      	}
      
      	public void setUserNotes(Set userNotes) {
      		this.userNotes = userNotes;
      	}
      
      	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
      	public Set getUserAddresses() {
      		return this.userAddresses;
      	}
      
      	public void setUserAddresses(Set userAddresses) {
      		this.userAddresses = userAddresses;
      	}
      
      	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
      	public Set getUserPhones() {
      		return this.userPhones;
      	}
      
      	public void setUserPhones(Set userPhones) {
      		this.userPhones = userPhones;
      	}
      
      	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
      	public Set getUserEmails() {
      		return this.userEmails;
      	}
      
      	public void setUserEmails(Set userEmails) {
      		this.userEmails = userEmails;
      	}
      
      }

      Comment


      • #4
        have you mapped your class in session factory?

        Code:
        <bean id="sessionFactory"
         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
          <property name="dataSource" ref="dataSource" />
           <property name="annotatedClasses">
           <list>
            <value>com.rottmanj.domain.user.UserAccount</value>
           </list>
          </property>
          
         </bean>
        look at the part marked in red.

        Comment

        Working...
        X