Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8317305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:33:42+00:00 2026-06-08T21:33:42+00:00

I’m getting this exceptions: javax.el.ELException: Error reading ‘id’ on type com.example.model.Article_$$_javassist_2 … org.hibernate.LazyInitializationException: could

  • 0

I’m getting this exceptions:

javax.el.ELException: Error reading 'id' on type com.example.model.Article_$$_javassist_2
...

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
com.example.model.Article_$$_javassist_2.getId(Article_$$_javassist_2.java)
...

Here’s my code:

@Entity
@Table( name = "tbl_articles" )
public class Article implements Comparable<Article>, Serializable
{
    private static final long serialVersionUID = 1L;

    @Id
    @Column( nullable = false )
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    private Integer id;

    // some other fields

    @ManyToMany( cascade = { CascadeType.ALL } )
    @JoinTable( name = "tbl_articles_categories",
        joinColumns = { @JoinColumn( name = "article_id" ) },
        inverseJoinColumns = { @JoinColumn( name = "category_id" ) })
    @ForeignKey( name = "tbl_articles_categories_fkey_article",
        inverseName = "tbl_articles_categories_fkey_category" )
    private Set<Category> categories = new HashSet<Category>();

    @ManyToMany( cascade = { CascadeType.ALL } )
    @JoinTable( name = "tbl_articles_tags",
        joinColumns = { @JoinColumn( name = "article_id" ) },
        inverseJoinColumns = { @JoinColumn( name = "tag_id" ) })
    @ForeignKey( name = "tbl_articles_tags_fkey_article",
        inverseName = "tbl_articles_tags_fkey_tag" )
    private Set<Tag> tags = new HashSet<Tag>();

    // getters and setters
}

public abstract class BaseService<E, D extends BaseDAO<E>>
{
    protected D dao;

    public BaseService()
    {
    }

    protected D getDao()
    {
        return dao;
    }

    @Autowired
    protected void setDAO( D dao )
    {
        this.dao = dao;
    }

    @Transactional
    public E get( int id )
    {
        return dao.get( id );
    }
}

@Service
public class ArticleService extends BaseService<Article, ArticleDAO>
{
    public ArticleService()
    {
        setDAO( dao );
    }
}

public abstract class BaseDAO<E>
{
    public abstract E get( int id );
}

@Repository
public class ArticleDAO extends BaseDAO<Article>
{
    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public Article get( int id )
    {
        return ( Article ) sessionFactory.getCurrentSession().load( Article.class, id );
    }
}

In my Controller now, I’m using this to get a specific article:

@RequestMapping( "/{id}/{title}.html" )
public String article( @PathVariable( "id" ) Integer id, Map<String, Object> map )
{
    map.put( "article", articleService.get( id ) );
    return "article";
}

Which I’m using in my JSP just like this:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="slg" uri="http://github.com/slugify" %>
<article>
    <c:url value="/blog/${article.id}/${slg:slugify(article.title)}.html" var="articleUrl" />
    <h2><a href="${articleUrl}">${article.title}</a></h2>
    <span><fmt:formatDate value="${article.creationDate}" pattern="E, dd MMM yyyy" /></span>
    <p>
        ${article.text}
    </p>
</article>

Here’s my hibernate configuration as well:

# Properties file with Hibernate Settings.

#-------------------------------------------------------------------------------
# Common Settings

hibernate.generate_statistics=false
#hibernate.hbm2ddl.auto=update
hibernate.show_sql=false

#-------------------------------------------------------------------------------
# DB specific Settings

# Property that determines which Hibernate dialect to use
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

What I’m doing wrong?

UPDATE

Debugging sessionFactory.getCurrentSession() results in:

DEBUG : com.example.model.ArticleDAO - SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])

I’m adding some global variables, maybe this causing the errors? In my controller there’s a method:

@ModelAttribute
public void addGlobalObjects( Map<String, Object> map )
{
    map.put( "section", "blog" );

    SortedMap<Category, Integer> categories = new TreeMap<Category, Integer>();
    for ( Category category : categoryService.list() )
    {
        categories.put( category, articleService.size( category ) );
    }

    Calendar cal = Calendar.getInstance();
    cal.set( Calendar.DAY_OF_MONTH, 1 );

    cal.add( Calendar.MONTH, ARCHIVE_MONTHS * -1 );

    SortedMap<Date, Integer> archive = new TreeMap<Date, Integer>();
    for ( int i = 0; i < ARCHIVE_MONTHS; ++i )
    {
        cal.add( Calendar.MONTH, 1 );
        archive.put( cal.getTime(), articleService.size( cal ) );
    }

    SortedMap<Tag, Integer> tags = new TreeMap<Tag, Integer>();
    for ( Tag tag : tagService.list() )
    {
        tags.put( tag, articleService.size( tag ) );
    }

    map.put( "categories", categories );
    map.put( "archive", archive );
    map.put( "tags", tags );

    map.put( "categoriesSize", categoryService.size() );
    map.put( "tagsSize", tagService.size() );

    map.put( "date", new Date() );
}

For updated article entity see above.

UPDATE2

Eager fetching didn’t solved the problem – still the same exception:

@ManyToMany( fetch = FetchType.EAGER, cascade = { CascadeType.ALL } )

And finally I’m getting duplicated articles what I don’t need…

UPDATE3

Trying Hibernate.initialize() I’m getting this exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: could not initialize proxy - no Session

UPDATE4

I changed my get method this way:

@Override
public Article get( int id )
{
    // return ( Article ) sessionFactory.getCurrentSession().load( Article.class, id );
    return ( Article ) sessionFactory.getCurrentSession().createCriteria( Article.class ).add( Restrictions.eq( "id", id ) ).uniqueResult();
}

This is NOT a solution, but as I can’t handle this problem I’ll use this temporarily.

I already tried this (as mentioned here) without success (it changed the ELException from Error reading 'id' on type ... to Error reading 'title' on type ... – maybe i used it wrong?):

@Override
public Article get( int id )
{
    Article ret = ( Article ) sessionFactory.getCurrentSession().load( Article.class, id );
    sessionFactory.getCurrentSession().update( ret );
    return ret;
}

A solution is still needed!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:33:44+00:00Added an answer on June 8, 2026 at 9:33 pm

    This did the trick!

    Changed ArticleDAO.get from

    @Override
    public Article get( int id )
    {
        return ( Article ) sessionFactory.getCurrentSession().load( Article.class, id );
    }
    

    to

    @Override
    public Article get( int id )
    {
        Article ret = ( Article ) sessionFactory.getCurrentSession().get( Article.class, id );
        if ( ret == null )
        {
            ret = ( Article ) sessionFactory.getCurrentSession().load( Article.class, id );
        }
    
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.