Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am unable to reproduce the behaviour you are seeing. Here is my code:</p> <pre><code>@Entity public class Foo { private Long id; private String name; private Bar bar; public Foo() { } public Foo(String name) { this.name = name; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Basic public String getName() { return name; } public void setName(String name) { this.name = name; } @ManyToOne(fetch = FetchType.LAZY) public Bar getBar() { return bar; } public void setBar(Bar bar) { this.bar = bar; } } @Entity public class Bar { private Long id; private String name; public Bar() { } public Bar(String name) { this.name = name; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Basic public String getName() { return name; } public void setName(String name) { this.name = name; } } public void testGets() { SessionFactory sf = new AnnotationConfiguration() .addPackage("hibtest") .addAnnotatedClass(Foo.class) .addAnnotatedClass(Bar.class) .configure().buildSessionFactory(); Session session = null; Transaction txn = null; // Create needed data try { session = sf.openSession(); txn = session.beginTransaction(); // Create a Bar Bar bar = new Bar("Test Bar"); session.save(bar); // Create a Foo Foo foo = new Foo("Test Foo"); session.save(foo); foo.setBar(bar); txn.commit(); } catch (HibernateException ex) { if (txn != null) txn.rollback(); throw ex; } finally { if (session != null) session.close(); } // Try the fetch try { session = sf.openSession(); Foo foo = (Foo) session.get(Foo.class, 1L); Bar bar = (Bar) session.get(Bar.class, 1L); System.out.println(bar.getName()); } finally { if (session != null) session.close(); } } </code></pre> <p>And it all works fine, as one would expect.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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