Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2012
    Posts
    5
    Blog Entries
    1
    Rep Power
    0

    Default How to set list value to entity?

    Hi all,
    I have 2 DTOs & 2 Entities, 1 controller & 1 service implementation over here.

    Now, my problem is at the service implementation setStates. I dont know how to set states to address entity from addressDTO's getStatesList. because address entity includes state entity while addressDTO using stateDTO .

    My Address Entity:
    Java Code:
    public class Address
    {
        private List<State> states;
    
        public List<State> getStates()
        {
            return states;
        }
    
        public void setStates(List<State> states)
        {
            this.states = states;
        }
    }
    My Address DTO:
    Java Code:
    public class AddressDTO
    {
        private List<StateDTO> statesList;
    
        public List<StateDTO> getStatesList()
        {
            return statesList;
        }
    
        public void setStatesList(List<StateDTO> statesList)
        {
            this.statesList = statesList;
        }
    }
    My StateDTO:
    Java Code:
    public class StateDTO
    {
        private StateTypeEnum stateType;
    
        private Map<String, String> stateAttr;
    
        public StateTypeEnum getStateType()
        {
            return stateType;
        }
        public void setStateType(StateTypeEnum stateType)
        {
            this.stateType = stateType;
        }
        public Map<String, String> getCertificationAttr()
        {
            return stateAttr;
        }
        public void setStateAttr(Map<String, String> stateAttr)
        {
            this.stateAttr = stateAttr;
        }
    }
    My State entity:
    Java Code:
    public class State
    {
        private StateTypeEnum stateType;
        private Blob stateLogo;
        private Map<String, String> stateAttr;
    
        public StateTypeEnum getStateType()
        {
            return stateType;
        }
        public void setStateType(StateTypeEnum stateType)
        {
            this.stateType = stateType;
        }
        public Blob getStateLogo()
        {
            return stateLogo;
        }
        public void setStateLogo(Blob stateLogo)
        {
            this.stateLogo = stateLogo;
        }
        public Map<String, String> getStateAttr()
        {
            return stateAttr;
        }
        public void setStateAttr(Map<String, String> stateAttr)
        {
            this.stateAttr = stateAttr;
        }
    }
    My controller:
    Java Code:
        private void submitAddress(AddressDTO addressDTO)
        { AddressService.createAddress(addressDTO); }
    My service implementation:
    Java Code:
        public void createAddress(AddressDTO addressDTO)
        {
            Address address = new Address();
    
           [B] address.setStates(addressDTO.getStatesList());[/B]
            AddressDAO.createAddress(address);
        }


    Please guide..
    Last edited by heart_throbber; 03-03-2012 at 09:26 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to set value to entity?

    how to set states to address entity from addressDTO's getStatesList.
    Where is the data and where do you want to access it from?
    At the place you want to access the data, you need a reference to the place that the data is located.

  3. #3
    Join Date
    Mar 2012
    Posts
    5
    Blog Entries
    1
    Rep Power
    0

    Default Re: How to set value to entity?

    Quote Originally Posted by Norm View Post
    Where is the data and where do you want to access it from?
    At the place you want to access the data, you need a reference to the place that the data is located.
    the data will be passed from a form and will be stored temporarily to addressDTO. then, the addressDTO.getStatesList will get the value and and need to set it to entity address.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to set value to entity?

    Can you pass a reference to the class that is holding the data to the class that needs to access the data?

    Or can the class with the data get a reference to the class that wants the data and call the settor method to pass the data?

  5. #5
    Join Date
    Mar 2012
    Posts
    5
    Blog Entries
    1
    Rep Power
    0

    Default Re: How to set value to entity?

    Quote Originally Posted by Norm View Post
    Can you pass a reference to the class that is holding the data to the class that needs to access the data?

    Or can the class with the data get a reference to the class that wants the data and call the settor method to pass the data?
    Sorry..coundnt understand what are you trying to say. im a newbie to java.
    Are you saying that its imposibble. if so, how my method should be pls...

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to set value to entity?

    If it is possible to pass a reference of a class to another class, then the second class can call a method in the first class.

    You need to find a way for the class that needs the data to get a reference to the class that has the data.

  7. #7
    Join Date
    Mar 2012
    Posts
    5
    Blog Entries
    1
    Rep Power
    0

    Default Re: How to set value to entity?

    Quote Originally Posted by Norm View Post
    If it is possible to pass a reference of a class to another class, then the second class can call a method in the first class.

    You need to find a way for the class that needs the data to get a reference to the class that has the data.
    that is where i stucked. i dont know how to relate those 2 classes..

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to set value to entity?

    Where is an instance of each class created or available?
    If there is one method that creates or has access to instances of each, it could pass a reference of one to the other.

Similar Threads

  1. jpa entity update
    By videanuadrian in forum Advanced Java
    Replies: 14
    Last Post: 06-14-2011, 05:18 PM
  2. Entity - Free For All
    By entity in forum Introductions
    Replies: 0
    Last Post: 11-15-2010, 10:09 AM
  3. PK for Entity beans
    By eva in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 07-17-2008, 11:03 AM

Posting Permissions

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