3

I am using Hibernate(3.0) + Oracle DB (10g) for my application.

My domain object are like PluginConfig.java

@Entity
@Table(name = "plugin_config" , schema = "test")
@org.hibernate.annotations.Cache(usage =org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
public class Config {

private static final long serialVersionUID = -1959019321092627830L;

/** This object's id */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;

@OneToOne
@JoinColumn(name = "plugin_id")
private Plugin plugin;

@Column(name = "config_name")
@NaturalId(mutable = true)
private String name;

@Column(name = "config_desc")
private String description;

another domain object Plugin.java

@Entity
@Table(name = "plugin", schema = "test")
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
public class Plugin implements Serializable {

private static final long serialVersionUID = 5694761325202724778L;

/** This object's id */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;

@Column(name = "plugin_name")
@NaturalId
private String pluginName;
@OneToOne
@JoinColumn(name = "plugin_config_id")
private PluginConfig pluginConfig;

@Column(name = "plugin_desc")
private String description;

Whenever i try to load Plugin via my database service method(using @Transactional annotation and hence it loads all its children as well) i get the following error

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [PluginConfig#53]

There is actually no row in plugin_config table with id = 53. And also no plugin table entry has plugin_config_id=53.

So from where is hibernate picking these values ? I noticed one thing here, the value "53" is actually the row number from the plugin_config table which should have been reffered.

See the below image:

enter image description here

This is the plugin config that my query should be looking for. But it tries to search it with identifier #53(Row no:) instead of the #95(value of the primary key "id").

Where can i be going wrong with this ?

6
  • See the image here! [1]: i.sstatic.net/hVpob.png Commented Aug 25, 2013 at 14:34
  • Does the corresponding object based on the plugin_config_id exists at all? How are you trying to load the entity in the plugin_config table? Commented Aug 25, 2013 at 14:56
  • How are you generating your table id's? Commented Aug 25, 2013 at 15:00
  • @c.s. : Yes! the object based on plugin_config_id exists with identifier #95 but not with #53(which hibernate is looking for). Commented Aug 25, 2013 at 16:28
  • I'm loading the plugin_config(Child object) by loading plugin(Parent object) via hibernate criteria. The method with criteria has @Transactional annotation with it. Commented Aug 25, 2013 at 16:39

1 Answer 1

1

I don't know if this is teh best solution, but you can use @NotFound annotation with IGNORE command to let Hibernate discard exception adn set pluginConfig to null.

@OneToOne
@JoinColumn(name = "plugin_config_id")
@NotFound(action = NotFoundAction.IGNORE)
private PluginConfig pluginConfig;
Sign up to request clarification or add additional context in comments.

1 Comment

Sadly that's not an option for me. in this particular case i could have gone for this, but i have a whole application where i'm facing the same issue. i need some other workaround for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.