1

I dont know why but when I import this project to Eclipse. This work well.

So, I think this is problem of eclipse project when import to InteliJ IDEA


This not easy such my imagine.

I have class Setting and Setting.hbm.xml for mapping hibernate. In this class:

<hibernate-mapping>
<class name="Setting" table="setting" lazy="false">
    <id name="id" column="id" type="integer">
        <generator class="increment" />
    </id>

    .....
</class>

<query name="select.setting">
    from Setting as s where s.id = ? order by s.name
</query>

Now, when I call function

this.getHibernateTemplate().findByNamedQuery("select.setting", params);

This return error

org.springframework.orm.hibernate4.HibernateSystemException: Named query not known: select.setting; nested exception is org.hibernate.MappingException: Named query not known: select.setting
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:218) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:343) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.orm.hibernate4.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:933) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]

Please give advice about it.

6
  • Possible duplicate qtn. Check this link stackoverflow.com/questions/26084031/… Commented Dec 2, 2015 at 10:01
  • It not duplicate bro. Please check again Commented Dec 2, 2015 at 10:03
  • Does the name of the query without dot give the same result ? (Say : "selectSetting" instead of "select.setting", for example). Commented Dec 2, 2015 at 10:06
  • Have you included the hbm in the session? Commented Dec 2, 2015 at 10:14
  • Yes, I use spring boot and already set mapping @Bean public LocalSessionFactoryBean sessionFactory() throws Exception { LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); sessionFactory.setHibernateProperties(hibernateProperties()); sessionFactory.setMappingDirectoryLocations(new ClassPathResource[] { new ClassPathResource("data/model") }); Commented Dec 2, 2015 at 10:21

2 Answers 2

1

You can give a try with this.

<query name="select.setting">
    <![CDATA[from Setting as s where s.id = ? order by s.name]]>
</query>
Sign up to request clarification or add additional context in comments.

Comments

0

The XML parser gets confused of you are not using CDATA tag. CDATA is way of telling the framework that its a data which should not be interpreted as a markup.

Hence as @Lovababu mentioned, include the query inside CDATA tags:

<query name="select.setting">
<![CDATA[from Setting as s where s.id = ? order by s.name]]>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.