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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:27:22+00:00 2026-05-24T01:27:22+00:00

i use java hibernate i have 2 Tables Table1 and Table2 with many to

  • 0

i use java hibernate

i have 2 Tables Table1 and Table2 with many to many relationship

Table1:

@Entity
@Table(name="table1")
public class Table1 implements Serializable {
....
@ManyToMany(mappedBy="table1")
@JoinTable(
    name="table1_table2",
    joinColumns={@JoinColumn(name="table2_id")},
    inverseJoinColumns={@JoinColumn(name="table1_id")})
Set<Table2>table2;

@Column()
String column1;

@Column()
String column2;
....
and getter and setter methods
}

Table2:

@Entity
@Table(name="table2")
public class Table2  implements Serializable{
....
@ManyToMany(targetEntity=Table1.class,cascade = { CascadeType.ALL })
@Column(name="table1_id")
Set<Table1>table1;
....
and getter and setter methods
} 

Problem:

when i try to create a query from spring project, i get this error

error:

No value specified for parameter 4.
exception thrown < Table1.getByTable2AndColumn1(..) > exception message could not execute query with params [Table2 [....],..., ... ]   
at org.hibernate.exception.DataException: could not execute query           
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
.....
Caused by: org.postgresql.util.PSQLException: No value specified for parameter 4.
at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:146)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:183)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)

query inside function:

....
@Autowired
SessionFactory sessionFactory;

    .....
public Table1 getByTable2AndColumn1(Table2 table2, String column1, String column2) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Table1.class);

    if (table2 == null){
        criteria.add(Restrictions.isNull("table2"));
    }else{
        criteria.add(Restrictions.eq("table2", table2));
    }

    if (column1 == null){
        criteria.add(Restrictions.or(Restrictions.isNull("column1"), Restrictions.eq("column1", "")));
    }else{
        criteria.add(Restrictions.eq("column1", column1));
    }

    if (column2==null){
        criteria.add(Restrictions.isNull("column2"));
    }else{
        criteria.add(Restrictions.eq("column2", column2));
    }

    criteria.setMaxResults(1);


    return (Table1) criteria.uniqueResult();
}
 ....

can any one tell me where is the error

Note: when i remove node from this query no error occurs.

  • 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-05-24T01:27:22+00:00Added an answer on May 24, 2026 at 1:27 am

    change query to

    public Table1 getByTable2AndColumn1(Table2 table2, 
                                         String column1, String column2) {
    
    Criteria criteria = sessionFactory.getCurrentSession()
                                      .createCriteria(Table1.class);
    
    if (table2 == null){
        return null;
    }
    
    if (column1 == null){
        criteria.add(Restrictions.or(Restrictions.isNull("column1"), 
                                                   Restrictions.eq("column1", "")));
    }else{
        criteria.add(Restrictions.eq("column1", column1));
    }
    
    if (column2==null){
        criteria.add(Restrictions.isNull("column2"));
    }else{
        criteria.add(Restrictions.eq("column2", column2));
    }
    
    Criteria c = criteria.createCriteria("table2");
    c.add(Restrictions.eq("id", table2.getId()));
    c.setMaxResults(1);
    
    return (Table1) c.uniqueResult();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the BlogPost model : @Entity @Table(name = blog_posts) public class BlogPost extends
If i have a @OneToMany relationship with @Cascade(CascadeType.SAVE_UPDATE) as follows public class One {
Assuming the following mappings are provided: <class name=A table=a_table> <id name=id/> <many-to-one name=entityB column=fk_B
I'm trying to use many-to-many relation in Hibernate Framework, but I have some troubles.
My database contains 3 tables: User and Service entities have many-to-many relationship and are
I'm converting an application to use Java 1.5 and have found the following method:
Every class that wants to use java.util.logging generally needs to declare a logger like
Is there any tricky way to use Java reserved words as variable, method, class,
It seems like many OO discussions use Java or C# as examples (e.g. Head
I have a hibernate object that gets detached and transferred to a thick java

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.