Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate error
    primarykey
    data
    text
    <p>I did a small example program to insert data to a MySQL database table using java Hibernate. Every thing went fine &amp; I got the result</p> <p>"INFO: schema update complete Hibernate: insert into items (itemcode, itemdiscription, itemprice, itemId) values (?, ?, ?, ?) BUILD SUCCESSFUL (total time: 2 seconds)"</p> <p>My mapping file &amp; config file are OK. But when I'm running the query in command prompt to fetch updated values it doesn't show entered values by my java pojo class. Why is that??? Please consider I have used netbeans 7.1 for this.</p> <p>Mapping file </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt; &lt;hibernate-mapping&gt; &lt;class name="firsthibernetapp.Item" table="items"&gt; &lt;id name="iid" type="int" column="itemId" &gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;property name="icode"&gt; &lt;column name="itemcode"/&gt; &lt;/property&gt; &lt;property name="idiscription"&gt; &lt;column name="itemdiscription"/&gt; &lt;/property&gt; &lt;property name="iprice"&gt; &lt;column name="itemprice"/&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>hibernet.cfg.xml file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt; &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306 /combo&lt;/property&gt; &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt; &lt;property name="hibernate.connection.password"&gt;********&lt;/property&gt; &lt;property name="hibernate.connection.pool_size"&gt;10&lt;/property&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt; &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt; &lt;mapping resource="hibernate.hbm.xml"/&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>Code: </p> <pre><code>package firsthibernetapp; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class FirstHibernetApp { public static void main(String[] args) { Session session = null; try{ SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); Item item = new Item(); System.out.println("Inserting Record"); item.setIid(5); item.setIcode("FX00010"); item.setIdiscription("Apple"); item.setIprice(10); session.save(item); System.out.println("Done"); }catch(Exception e){ System.out.println(e.getMessage()); } finally{ session.flush(); session.close(); } } } </code></pre> <p>`</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload