Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: Exception while working with Spring Templates and Hibernate

  1. #21
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    As I mentioned userDTO != userDTO1... And please use code tags...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  2. #22
    Join Date
    Aug 2011
    Posts
    28

    Default

    userDTO1 is an object of UserDTO as you can see. and userDTO is also an object of UserDTO too.

    here is UserDTO

    Code:
    package com.peanuts.blackboard.database.dto;
    /**
     * @version=1.0
     * @author vbinda
     * 
     */
    public class UserDTO {
    	
    	private int userId;
    	private String userName;
    	private int userSchoolId;
    	private String userPassword;
    	private String userRole;
    	private String userStatus;
    	private UserPersonalInfoDTO userPersonalInfoDTO;
    	
    	public int getUserId() {
    		return userId;
    	}
    	public void setUserId(int userId) {
    		this.userId = userId;
    	}
    	public String getUserName() {
    		return userName;
    	}
    	public void setUserName(String userName) {
    		this.userName = userName;
    	}
    	public int getUserSchoolId() {
    		return userSchoolId;
    	}
    	public void setUserSchoolId(int userSchoolId) {
    		this.userSchoolId = userSchoolId;
    	}
    	public String getUserPassword() {
    		return userPassword;
    	}
    	public void setUserPassword(String userPassword) {
    		this.userPassword = userPassword;
    	}
    	public String getUserRole() {
    		return userRole;
    	}
    	public void setUserRole(String userRole) {
    		this.userRole = userRole;
    	}
    	public String getUserStatus() {
    		return userStatus;
    	}
    	public void setUserStatus(String userStatus) {
    		this.userStatus = userStatus;
    	}
    	public UserPersonalInfoDTO getUserPersonalInfoDTO() {
    		return userPersonalInfoDTO;
    	}
    	public void setUserPersonalInfoDTO(UserPersonalInfoDTO userPersonalInfoDTO) {
    		this.userPersonalInfoDTO = userPersonalInfoDTO;
    	}
    
    }
    and userPersonalInfoDTO
    Code:
    package com.peanuts.blackboard.database.dto;
    
    public class UserPersonalInfoDTO {
    	
    	private int userId;
    	private String userFirstName;
    	private String userLastName;
    	private String userEmail;
    	private String userContactNumber;
    	private String userAddress;
    	private UserDTO userDTO;
    	
    	
    	public int getUserId() {
    		return userId;
    	}
    	public void setUserId(int userId) {
    		this.userId = userId;
    	}
    	public String getUserFirstName() {
    		return userFirstName;
    	}
    	public void setUserFirstName(String userFirstName) {
    		this.userFirstName = userFirstName;
    	}
    	public String getUserLastName() {
    		return userLastName;
    	}
    	public void setUserLastName(String userLastName) {
    		this.userLastName = userLastName;
    	}
    	public String getUserEmail() {
    		return userEmail;
    	}
    	public void setUserEmail(String userEmail) {
    		this.userEmail = userEmail;
    	}
    	public String getUserContactNumber() {
    		return userContactNumber;
    	}
    	public void setUserContactNumber(String userContactNumber) {
    		this.userContactNumber = userContactNumber;
    	}
    	public String getUserAddress() {
    		return userAddress;
    	}
    	public void setUserAddress(String userAddress) {
    		this.userAddress = userAddress;
    	}
    
    	public UserDTO getUserDTO() {
    		return userDTO;
    	}
    	public void setUserDTO(UserDTO userDTO) {
    		this.userDTO = userDTO;
    	}
    }
    it does not matter If i name the object usr or usr1 or userDTO1 or usrDTO, If my objects and named correctly in POJO classes. userDTO1 will be set to userDTO in pojo.

    Just to make you happy i changed userDTO1 to userDTO. It still throws the same exception.

  3. #23
    Join Date
    Aug 2011
    Posts
    28

    Default

    Is someone still there to help, the problem is not yet resolved.

  4. #24
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Sigh... I give up... You really don't have a clue what I'm saying (or I'm writing some not to understand English) or how hibernate relation mappings work.

    It doesn't matter if both are instances of UserDTO they have to be the SAME instance.. That is what I tried to explain each post, but apparently miserable failed.

    I suggest a read of this about bidirectional mappings.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #25
    Join Date
    Aug 2011
    Posts
    28

    Default

    Dear Marten,

    I totally understand what you are trying to say.

    I am using the same instance of UserDTO. I just had it named that way. I corrected it and It is still throwing up the same error.

  6. #26
    Join Date
    Aug 2011
    Posts
    28

    Default

    this was the mistake which you pointed out

    Code:
    UserDTO userDTO1 = new UserDTO();
    userDTO1.setUserName("test");
    userDTO1.setUserPassword("temp");
    userDTO1.setUserRole("STUDENT");
    userDTO1.setUserSchoolId(3333);
    userDTO1.setUserStatus("ACTIVE");
    
    
    UserPersonalInfoDTO userPersonalInfoDTO = new UserPersonalInfoDTO();
    userPersonalInfoDTO.setUserAddress("test");
    userPersonalInfoDTO.setUserContactNumber("3333333" );
    userPersonalInfoDTO.setUserEmail("test");
    userPersonalInfoDTO.setUserFirstName("test");
    userPersonalInfoDTO.setUserLastName("test");
    
    userDTO.setUserPersonalInfoDTO(userPersonalInfoDTO );
    userPersonalInfoDTO.setUserDTO(userDTO1);
    
    
    session.save(userDTO);
    it has been corrected to

    Code:
    UserDTO userDTO = new UserDTO();
    userDTO.setUserName("test");
    userDTO.setUserPassword("temp");
    userDTO.setUserRole("STUDENT");
    userDTO.setUserSchoolId(3333);
    userDTO.setUserStatus("ACTIVE");
    
    
    UserPersonalInfoDTO userPersonalInfoDTO = new UserPersonalInfoDTO();
    userPersonalInfoDTO.setUserAddress("test");
    userPersonalInfoDTO.setUserContactNumber("3333333" );
    userPersonalInfoDTO.setUserEmail("test");
    userPersonalInfoDTO.setUserFirstName("test");
    userPersonalInfoDTO.setUserLastName("test");
    
    userDTO.setUserPersonalInfoDTO(userPersonalInfoDTO );
    userPersonalInfoDTO.setUserDTO(userDTO);
    
    
    session.save(userDTO);
    it still throws the same error..

  7. #27
    Join Date
    Aug 2011
    Posts
    28

    Default

    If I have understood correctly from the documentation, below code is enough to manage transactions. untill and unless I want to do something special, I would have to add advice on class level, method level etc.

    Code:
    <annotation-driven />
    <beans:bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    	<tx:annotation-driven proxy-target-class="true"
    		mode="proxy" />
    and this is my transaction manager

    Code:
    <beans:bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<beans:property name="sessionFactory" ref="sessionFactory" />
    	</beans:bean>
    because the name is transactionManager i dont need to specify its name in proxy-target-class bean all i need now id add @Transactional to my class.

    Any way, I have tried adding advice to the method also. It is still the same.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •