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 8945501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:15:38+00:00 2026-06-15T12:15:38+00:00

I set up a Database Application with Spring an Hibernate and I’m using a

  • 0

I set up a Database Application with Spring an Hibernate and I’m using a Many-To-Many-Relationship.
Here’s the code:

Author.java

@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "writes", joinColumns = {@JoinColumn(name = "authorId")}, inverseJoinColumns = {@JoinColumn(name = "publicationId")})
private Set<Publication> publications = new HashSet<Publication>();

Publication.java

@ManyToMany(mappedBy = "publications")
private Set<Author> authors = new HashSet<Author>();

these lines of code generate a connection-table named writes, but when I try to run a query over all Tables int gives me the error, named above.

this is the method, that schould run the query:

@Transactional
public List<Author> findAuthorByLastname(String lastName) {
    String hql = "from Author a, Publication p, writes w where a.id = w.authorId and p.id = w.publicationId and a.lastname = :lastName";
    Query q = sessionFactory.getCurrentSession().createQuery(hql);
    q.setParameter("lastName", lastName);
    List<Author> result = q.list();
    return result;
}
  • 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-15T12:15:40+00:00Added an answer on June 15, 2026 at 12:15 pm

    You don’t need to mention connection table explicitly in HQL queries (moreover, you even cannot mention them – only mapped entities). You need to use join on mapped relationships instead.

    Also, it’s not quite clear what you want to achieve.

    • If you want to fetch Authors with eagerly filled collections of their Publications in one query, use join fetch:

      select distinct(a) from Author a join fetch a.publications where a.lastName = :lastName
      
    • If you want to fetch a list of pairs (Author, Publication), use regular join:

      select a, p from Author a join a.publications p where a.lastName = :lastName
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using hibernate application in java to retrieve and update database. During updating
I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I'm writing a small demo application in Java using Spring, that needs to have
I have a Spring, Hibernate, and Wicket application set up to read internationalized json
I've got my database set up with three tables - code, tags, and code_tags
I have a JPA/Spring application that uses Hibernate as the JPA provider. In one
I use JPA/Hibernate with Spring transaction management in my application. There is a InspectionEntity
I have an application that uses Hibernate/JPA, with Spring and Jersey. In my application
I am developing a new web application with Struts2, Spring and Hibernate as its
I've been having loads of problems trying to get a Spring/Hibernate web application to

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.