-
1. Re: Can't update primary key fields
tom_goring May 8, 2008 5:45 PM (in response to infprog2)I'm not sure I'd recommend (or even if it's valid) to change the PK of an EJB3 bean.
What I do in this situation is delete the old one and create a clone with the new key.
-
2. Re: Can't update primary key fields
tom_goring May 8, 2008 5:47 PM (in response to infprog2)also depends on your reason to update the key.... it may be a better idea to have a technical key (e.g. a long) and a business key (which is the one you update).
-
3. Re: Can't update primary key fields
andygibson.contact.andygibson.net May 8, 2008 5:49 PM (in response to infprog2)Chances are that you have the primary key or Id field marked with the @GeneratedValue annotation meaning that the value is generated from the database. I'm guessing that since the value is generated from the database, then JPA has no need to be concerned with updating it.
Some code relating to the entity bean might help,
Cheers,
Andy Gibson
-
4. Re: Can't update primary key fields
dmrc Jan 22, 2009 3:38 PM (in response to infprog2)Hello
i have same problem. my entity have id and i want its generated from database.
@Id @GeneratedValue public Long getId() { return id; }
And i want to update in user.xhtml but its doesnt work.
action="#{userHome.update}"
How can i solve this problem ?
-
5. Re: Can't update primary key fields
stefanotravelli Jan 22, 2009 8:09 PM (in response to infprog2)From
Mapping entities with identity, Hibernate In Action, p. 163
Hibernate (and JPA) doesn't allow you to change the identifier value of a persistent instance after it's first assigned. A primary key value never changes - otherwise the attribute wouldn't be a suitable primary key candidate! -
6. Re: Can't update primary key fields
dmrc Jan 22, 2009 8:32 PM (in response to infprog2)Hello i dont want update id value, i want update name and code values.
@Id @GeneratedValue public Long getId() { return id; } public void setId(Long id) { this.id = id; } @NotNull @Length(max = 20) public String getName() { return name; } public void setName(String name) { this.name = name; } @NotNull @Length(max=10) public String getCode() { return code; } public void setCode(String code) { this.code = code; }
<rich:panel> <f:facet name="header">fakulte</f:facet> <s:decorate id="nameField" template="layout/edit.xhtml"> <ui:define name="label">Fakulte Adi</ui:define> <h:inputText id="name" required="true" value="#{fakulteHome.instance.name}"/> </s:decorate> <s:decorate id="codeField" template="layout/edit.xhtml"> <ui:define name="label">Fakulte Kodu</ui:define> <h:inputText id="code" required="true" value="#{fakulteHome.instance.code}"/> </s:decorate> <div style="clear:both"/> </rich:panel> <h:commandButton id="update" value="Update" action="#{fakulteHome.update}" rendered="#{fakulteHome.managed}"/>
But its doenst work.
-
7. Re: Can't update primary key fields
luxspes Jan 22, 2009 9:06 PM (in response to infprog2)Nazmi Demirci, the person that initiated this thread wrote as subject:
Can't update primary key fields
, if you write:i have same problem
and the write:i don't want update id value, i want update name and code
that is a contradiction, you do not have the same problem, and that means you should have started your own thread.Also, saying
it does not work
is not the way to get help in an internet forum. You have to be specific, post the stack trace, or something that we can use to understand your problem. -
8. Re: Can't update primary key fields
dmrc Jan 22, 2009 10:04 PM (in response to infprog2)
Francisco Peredo wrote on Jan 22, 2009 21:06:
Nazmi Demirci, the person that initiated this thread wrote as subject:Can't update primary key fields
, if you write:i have same problem
and the write:i don't want update id value, i want update name and code
that is a contradiction, you do not have the same problem, and that means you should have started your own thread.
Also, sayingit does not work
is not the way to get help in an internet forum. You have to be specific, post the stack trace, or something that we can use to understand your problem.You are rigt Francisco Peredo. i am newbie. i have a litte time and i didnt careful. When i click update button , its doesnt update value in database.And its not giving error.