• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

@OneToMany problem with complex PK

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting an oracle error when I go to delete an object Dog from the DB, stating that Bark.id cannot be updated to NULL. The DB is set up to perform a cascade
delete on items in the table "Bark" when the Dog item w/ Dog.ID = Bark.ID is deleted, and this functionality is working correctly.

Thoughts? Thank you!

@Entity
@Table(name="DOG")
public class Dog {
Long id;
List<Bark> barks;

@Generated(a sequence..)
@Id
@Column(ID)
public Long getId() {
return this.id;
}

@OneToMany
@JoinColumn(name="id")
public List<Bark> getBarks() {
return this.barks;
}

// setters, etc...

}

@Entity
@Table(name="BARK")
public class Bark {
BarkPk pk;

@Id
public BarkPk getPk() {
return this.pk;
}

// setters, etc..

}

@Embeddable
public class BarkPk implements Serializable {
Long id;
String volume;

// this ID is a FK to the ID in Dog
@Column(name="ID")
public Long getId() {
...
}

@Column(name="VOLUME")
public String getVolume() {
...
}

// setters, etc...
}
 
Shannon McGee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I am able to save data and retrieve it (including "bark" items associated with a given "dog" item).
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would try two different things.

First try

@OneToMany
@JoinColumn(name="id", updatable=false, insertable=false)
public List<Bark> getBarks() {
return this.barks;
}

and if that doesn't work set a Cascade option for the mapping

@OneToMany
@Cascade([ALL, DELETE-ORPHAN])
@JoinColumn(name="id")
public List<Bark> getBarks() {
return this.barks;
}

or just

@OneToMany
@Cascade([DELETE-ORPHAN])
@JoinColumn(name="id")
public List<Bark> getBarks() {
return this.barks;
}

and let us know if any of them work for you.

Good Luck

Mark
 
Shannon McGee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither of those suggestions seemed to resolve my problem, but I have made some progress...

I've found that if I set "Bark" to fetchType=EAGER, my error is not thrown at Bark, but at the Volume.

I can't make Bark and Volume fetch type EAGER, b/c that causes new issues (only one fetchType=EAGER allowed per model).

I know that with the LAZY fetch type, you must access the data from the sub-tables for it to be loaded, so I am doing that. I can see that the data has been loaded into the Bark/ Volume items before the delete is executed.

I appreciate the input!
 
reply
    Bookmark Topic Watch Topic
  • New Topic