Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating SpringSource Tool Suite (STS) Hibernate Template
    text
    copied!<p>i've created the Hibernate project using Spring Template Project. Two domain objects, a JUnit test, app-context.xml and the persistence-context.xml were created. Now i noticed this line</p> <blockquote> <p><code>&lt;jdbc:embedded-database id="dataSource"&gt;&lt;/jdbc:embedded-database&gt;</code></p> </blockquote> <p>and assume that the following happens</p> <ol> <li>A default HQSL db is used</li> <li><p>The two created models Order.java &amp; Item.java will automatically created in memory tables T_ORDER and T_ITEM and the these will be mapped as per annotations on the objects. Inside the auto created classes one of the test methods is as follows </p> <pre><code>@Test @Transactional public void testSaveAndGet() throws Exception { Session session = sessionFactory.getCurrentSession(); Order order = new Order(); order.getItems().add(new Item()); session.save(order); session.flush(); // Otherwise the query returns the existing order // (and we didn't set the parent in the item)... session.clear(); Order other = (Order) session.get(Order.class, order.getId()); assertEquals(1, other.getItems().size()); assertEquals(other, other.getItems().iterator().next().getOrder()); } </code></pre></li> </ol> <p>Questions ...</p> <ol> <li>Am i correct to think that the in memory tables are created from the domain models (Order/Item), and mapped? Therefore session.flush() synchronize the object to the physical (in memory table)....</li> <li><p>Are these tables auto mapped because if i do the following</p> <pre><code>session.save(order); session.flush(); session.clear(); Order other = (Order) session .createQuery("from T_ORDER where ORDER_ID =: orderid") .setLong("orderid", order.getId()) .uniqueResult(); </code></pre></li> </ol> <p>i get an exception...</p> <pre><code>org.hibernate.hql.ast.[B]QuerySyntaxException[/B]: \ T_ORDER is not mapped [from T_ORDER where ORDER_ID =: orderid] ............ ............ </code></pre> <p>if these tables are not mapped automatically, how is flushing working at the first place?</p>
 

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