GithubHelp home page GithubHelp logo

arey / hibernate-hydrate Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 8.0 316 KB

Avoid Hibernate LazyInitializationException by recursively resolving proxy

Home Page: http://javaetmoi.com/2012/03/hibernate-dites-adieu-aux-lazy-initialization-exception/

License: Apache License 2.0

Java 100.00%
hibernate

hibernate-hydrate's People

Contributors

andrewcowlin-ibboost avatar arey avatar dependabot[bot] avatar markusheiden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hibernate-hydrate's Issues

Re-enable test if HHH-15713 has been fixed

Due to the Hibernate 6 bug HHH-15713 the test TestIssue3#listWithEmbeddableClass() fails and thus has been disabled.

Re-enable the test as soon as HHH-15713 has been fixed in Hibernate 6.

Debug spam

Version: hibernate4-hydrate 2.1

When I add this dependency to my project, all database queries are being logged as debug.

...
17:27:37.119 [main] DEBUG org.hibernate.SQL - select //... some query
17:27:37.120 [main] DEBUG o.h.l.p.e.p.i.ResultSetProcessorImpl - Preparing collection intializer : //... details
17:27:37.120 [main] DEBUG o.h.l.p.e.p.i.ResultSetProcessorImpl - Starting ResultSet row #0
17:27:37.120 [main] DEBUG o.h.l.p.e.p.i.CollectionReferenceInitializerImpl - Found row of collection: //... details
17:27:37.120 [main] DEBUG o.h.l.p.e.p.i.ResultSetProcessorImpl - Starting ResultSet row #1
...
...

Nested List are not hydrated using @MappedSuperclass annotation

I seem to be able to reproduce it here as well:

@MappedSuperclass
public abstract class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String number;
    private String name;
}

@Entity
@Table(name = "PARENT")
@AttributeOverrides(value = { @AttributeOverride(name = "id", column = @Column(name = "parentKey")) })
public class Parent extends Person {

    @OneToMany(mappedBy = "parent", orphanRemoval = true)
    @Cascade(CascadeType.ALL)
    @OrderBy(value = "number asc")
    private List<CHILD> children = new ArrayList<CHILD>();
}

@Entity
@Table(name = "CHILD")
public class Child extends Person {
    @ManyToOne
    @Cascade(CascadeType.ALL)
    @JoinColumn(name = "parentKey_FK", referencedColumnName = "parentKey")
    private Parent parent;
}

Children in this case aren’t auto initialized when the parent's are pulled in as a list.

Promotion of 1.2

Wish there was a better way to ask for this, is it possible to promote the current code base to 1.2 on cloudbees?

Please release

Hi Antoine,

can you please build a release?

BTW: Please update the link to my personal github account: "markusheiden". "markus-s24" may get deleted soon.

Thanks,
Markus

ManyToMany mappings don't always seem to get hydrated

Not getting hydrated entities for this mapping

@Entity
public class Foo {


    @ElementCollection
    @Fetch(FetchMode.SELECT)
    @OrderColumn(name = "elementOrder")
    @Cascade(CascadeType.ALL)
    @CollectionTable(name = "bars", joinColumns = @JoinColumn(name = "FOO_ID"))
    private List<Bar> bars = new ArrayList<Bar>();

...

@Embeddable
public class Bar implements Serializable {


    @ManyToOne
    @JoinColumn(name = "biz")
    @Cascade(CascadeType.ALL)
    private Biz biz;

...

@Entity
public class Biz {
    @ManyToMany
    @Fetch(FetchMode.SUBSELECT)
    @JoinTable(name = "Bat", joinColumns = @JoinColumn(name = "BarId), inverseJoinColumns = @JoinColumn(name = "batA"))
    @Cascade(value = { CascadeType.SAVE_UPDATE, CascadeType.DELETE })
    private List<Bat> bats = new ArrayList<Bat>();

Note: Bat is mapped with @MappedSuperclass in it's hierarchy

It looks like The list containing Bats is not being hydrated...

I'll try to provide some more details as I look into this.

ClassCastException, when use Proxy instead of Session

When use Proxy instead of Session I get the following error:

java.lang.ClassCastException: $Proxy65 cannot be cast to org.hibernate.impl.AbstractSessionImpl

In lines:
com.javaetmoi.core.persistence.hibernate.LazyLoadingUtil.deepInflateEntity()

Serializable identifier = classMetadata.getIdentifier(entity, (AbstractSessionImpl) currentSession);

But, if I change casting to SessionImplementor, there is no error:

Serializable identifier = classMetadata.getIdentifier(entity, (SessionImplementor) currentSession);

Doesn't work for me.

It doesn't work for - hibernate 5 and JPA (have a look at the screenshot) - the customer is hydrated, but not the address.
screenshot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.