Featured post
java - JPA 2, JSF, setting id of OneToOne mapped entity problem -
we havent used jpa or other orm tools in our web application, have been on updating whole stuff java ee 6,
problem jpa ,i have been looking answer,and learn how people solve kinda issue, have 2 entites,
@entity person { @id private long id; @joincolumn(name="city_id") @onetoone(fetch=fetchtype.lazy) private city city; .... }
and second entity
@entity city { @id private long id; private string name; ..... }
i querying person entity , show 1 on jsf page
i have 2 input fields person.city show on jsf page inputhidden id , inputtext name people selecting cities popup set hidden component city id, new selected new value, , same name, everthing goes fine till now, when merge person entity, tries merge city also, id defined on table, constraint error cirty id.
what doing kinda problem?
i thought valuechange action inputhidden,but @ jsf life cycle happens before update model if replace person.city entity new 1 in action , updated again (actually same values done twice) ,so best workaround situation?
thanx
you trying save new person , assign existing city? if so, , if using persistantmanager.persist(person) tries create new city, fails. can tell relationship person city options follow, see cascading (merge in case guess).
- Get link
- X
- Other Apps
Comments
Post a Comment