Loading related object in hibernate

335
January 12, 2017, at 05:56 AM

I would like to load House object which has many-to-one field type:

@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="type_id")
public Type getType() {
    return type;
}

I would like now to gain access to it like so:

House temp = DataBaseConnector.getInstance().findHouseByID(id);
Type type = temp.getType();

findHouseById() method looks like this:

public static House findHouseByID(Integer id) {
    Session session = getSessionFactory().openSession();
    House e = (House) session.load(House.class, id);
    session.close();
    return e;
}

But there I got an error:

Exception in thread "AWT-EventQueue-0" org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:286) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) at mapping.House_$$_jvst2a0_3.getType(House_$$_jvst2a0_3.java)

Any help would be appreciated :)

Rent Charter Buses Company
READ ALSO
Sailsjs MVC map params from external API to multiple models

Sailsjs MVC map params from external API to multiple models

I need to create a database of shopify orders so I can run advanced queries and sales reports that you can't do in the shopify admin areaI'm building in Sails

326
How to set auto increment field with a prefix MYSQL

How to set auto increment field with a prefix MYSQL

I have table called t1 with id field and name field

565
Value isn't assigned to variable in Responselistener

Value isn't assigned to variable in Responselistener

So, I'm trying to build and app in androidstudio and I want to retrieve some data from a mysql database and use this in the appI use a php script online and a responselistener to retrieve the data

340
Importing a file using Workbench returns 0 files when using column matching

Importing a file using Workbench returns 0 files when using column matching

I am completely new to SQLI asked that question 2 weeks ago but got no reply, so I am afraid I have to ask again

452