[Persistence, JBoss/CMP, Hibernate, Database] - trouble with bidirectional OneToMany and JoinColumn
by bernieb
I am trying to create a birectional OneToMany relationship.
When I attempt to populate a set of this relationship, the item gets inserted into the expected table, but its foreign key, which is supposed to get mapped to the owner of the item, is getting set as null instead.
Here's the code to the owner of the OneToMany relationship:
| @Entity
| public class Owner implements Serializable {
| private long id;
| private Set<Item> items;
|
| public Owner(){
| items = new HashSet<Item>();
| }
|
| @Id
| @GeneratedValue(strategy=GenerationType.AUTO)
| public long getId(){
| return id;
| }
| public void setId(long id){
| this.id = id;
| }
|
| @OneToMany(targetEntity=Item.class, cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
| @JoinColumn(name="id")
| public Set<Item> getItems(){
| return items;
| }
| public void setItems(Set<Item> items){
| this.items = items;
| }
| }
|
Here's the code to the Item class, the other end of the OneToMany relationship:
| @Entity
| @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
| @DiscriminatorColumn(name="DISCRIMINATOR")
| public class Item implements Serializable {
| private Owner owner;
| private String description;
|
| @Id
| public String getDescription(){
| return description;
| }
| public void setDescription(String description){
| this.description = description;
| }
|
| @ManyToOne(targetEntity=Owner.class)
| @JoinColumn(name="id", updatable = false, insertable = false)
| public Owner getOwner(){
| return owner;
| }
| public void setOwner(Owner owner){
| this.owner = owner;
| }
| }
|
Item also happens to contain inherited classes (stored with the single column and descriminator method), of which can be included in the set in owner. Also, description is a manually assigned primary key for items.
When an item is added to the set of an owner, a row is inserted into the Item table, but does not get associated to its owner-- the joined column 'id' remain null on the item's end.
Am I making an error with regard to the JoinColumn statements? Or am I doing something else wrong? Any help will be greatly appreciated. Thanks in advance for all your help.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976720#3976720
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976720
19 years, 7 months
[Beginners Corner] - Re: Newbie Need Help :)
by scout1lacno
My JBOSS just started working... but it shows an erorr
org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.mq:service=DestinationManager
Any idea with this erorr?
Thanks :)
anonymous wrote : org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.mq:service=DestinationManager
| at org.jboss.system.ServiceCreator.install(ServiceCreator.java:103)
| at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:449)
| at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:171)
| at org.jboss.system.ServiceController.install(ServiceController.java:226)
anonymous wrote : org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.mq:service=DestinationManager
| at org.jboss.system.ServiceCreator.install(ServiceCreator.java:103)
| at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:449)
anonymous wrote : 2006-10-07 09:57:53,210 DEBUG [org.jboss.deployment.scanner.URLDeploymentScanner] Failed to deploy: org.jboss.deployment.scanner.URLDeploymentScanner$DeployedURL@bef53c88{ url=file:/D:/jboss-4.0.4.GA/server/default/deploy/jms/mysql-jdbc2-service.xml, deployedLastModified=0 }
| org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.mq:service=DestinationManager
| at org.jboss.system.ServiceCreator.install(ServiceCreator.java:103)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976717#3976717
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976717
19 years, 7 months
[Persistence, JBoss/CMP, Hibernate, Database] - Invalid Schema Name in JBOSS EJB2.0
by smodou
Hi All,
I am trying to deploy some EJB2.0 beans that are currently running in Weblogic. I transformed the Weblogic specific DDs to their JBOSS equivalents.
After several debugging rounds, I have now successfully deployed all the beans (bundled along with a WAR in an EAR) in JBOSS4.0.4GA. However, when I access the application, I get an "Inavlid Schema Name" SQL exception on the following load relationship query:
SELECT USERNAME FROM foo.GROUP_OWNER WHERE (GROUPNAME=?)
The foo schema does exist and is owned and accessible by the user that connects the Datasource. In jbosscmp-jdbc.xml, the relationship is define as below:
<ejb-relation>
<ejb-relation-name>group-owner</ejb-relation-name>
<relation-table-mapping>
<table-name>foo.GROUP_OWNER</table-name>
</relation-table-mapping>
<ejb-relationship-role>
<ejb-relationship-role-name>users-own-groups</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>userName</field-name>
<column-name>USERNAME</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>groups-belongTo-users</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>name</field-name>
<column-name>GROUPNAME</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
Any ideas what may be causing this problem? I would appreciate any pointers.
regards,
Modou
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976714#3976714
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976714
19 years, 7 months