Hibernate Update giving java.lang.NullPointerException -


I am trying to code below, in fact I am trying to update a line in the database table by hibernate.

ABCEntity obj = new ABCEntity (); Obj.setMetal (MetalEnum.valueOf (Metal)); Obj.setName (smelter_name); Obj.setSmelterId (smelter_id); Obj.setReferenceName (smelter_name); Obj.setId ((tall) 117806); Try {// Getting known smileter table transactions in tx = sessionFactory.getCurrentSession (). BeginTransaction (); . SessionFactory.getCurrentSession () update (obj); Tx.commit (); } Hold (exception e) {logger.info ("print object" + obj.toString ()); Logger.info ("Error for updates:" + e.getMessage ()); }

So I'm seeing error log:

  print object ABCEntity @ 447a43f7 [id = 117806 name = XYZ SMELTER smelterId = ABC001 metal = METAL_A Context name = XYZ SMELTER nextSteps = & lt; Null & gt; MyNames = & lt; Null & gt; MineLocation = & lt; Null & gt; Comment = & lt; Null & gt; ]  

and

  error for update: empty  

what's the mistake here

You can try this sequence to update the line in the database using hibernate

1 Find the line you want to update, you can use a findByID () method

  public ABCEntity findById (integer ID) using the criteria {// TODO automatically generated method Stub {ABCEntity Example = (ABCENTit Y) getSession () Try .createcriteria (ABCEntity.class) .add (restriction ID (IDABCENTITY, id)). UniqueResult (); Return example; } Hold (runtime expiry) {throw away; }}  

use of hql

  public ABCEntity findById (integer ID) {// TODO automatically generated method stub {ABCEntity Example = (ABCEntity) GetSession () .get ("packageofclass.ABCEntity", id); Return example; } Hold (runtime expansion) {log. Terror ("failed", again); Throw away; }}  

Then reference to the object

  ABCEntity obj = findById (1);  

The second is that there should be a change in the field, for example I have to change the name

  obj.setName ("new name");  

Then to update the row that you can do

  Public zero update (ABCEntity transientInstance) {// TODO was automatically generated Method stub {getSession () .saveOrUpdate (transientInstance); Return transient instant; } Hold (runtime expansion) {re.printStackTrace (); Return tap; }}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -