Hibernate, Oracle, Sequence and One To Many Problem -
i having issue doing 1 line save on 1 many object. foreign key not populated in child objects. aren't suppose automatically hibernate? badgeid never gets inserted badgelevel.badgeid.
badge.java
@basic @id @generatedvalue(strategy=generationtype.sequence, generator="badge_sequence") @sequencegenerator(name="badge_sequence", sequencename = "badge_sequence") @column(name = "id", nullable=false, unique=true) public long getid() { return id; } @onetomany(mappedby="badge", fetch=fetchtype.eager, cascade=cascadetype.all) @fetch(value=fetchmode.select) public list<badgelevel> getbadgelevels() { return this.badgelevels; }
badgelevel.java
@basic @id @notnull @generatedvalue(strategy=generationtype.sequence, generator="badgelevel_sequence") @sequencegenerator(name="badgelevel_sequence", sequencename = "badgelevel_sequence") @column(name = "id", nullable=false, unique=true) public long getid() { return id; } @manytoone() @joincolumn(name = "badgeid") public badge getbadge() { return this.badge; } /** * set badge */ public void setbadge(badge badge) { this.badge = badge; }
before calling save on badge, try following
...... for(badgelevel badgelevel : badge.getbadegelevels() { badgelevel.setbadge(badge); } repo.save(badge);
Comments
Post a Comment