Intellij JPA Console with persistence.xml

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

I'm setting up a xml-free persistence JPA/Hibernate 4+/Spring 3+ using Intellij 13+. When I try to execute a query in the jpa console, I get the following error:

javax.persistence.PersistenceException: Unable to build entity manager factory java.lang.RuntimeException: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.PostgreSQL9Dialectt.PostgreSQL9Dialect] as strategy [org.hibernate.dialect.Dialect] 

With the default postgres dialect, I get the same error. Any idea what's going on?

Configuration extract:

<bean id="entityManagerFactory"       class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">     <property name="dataSource" ref="dataSource" />     <property name="packagesToScan" value="com.wikiz.service.model.rep" />     <property name="jpaVendorAdapter">         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />     </property>     <property name="jpaProperties">         <props>             <prop key="hibernate.dialect">${hibernate.dialect}</prop>             <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>             <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>             <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>             <prop key="jadira.usertype.autoRegisterUserTypes">true</prop>             <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>         </props>     </property> </bean>  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">     <property name="driverClassName" value="${db.driver}"/>     <property name="url" value="${db.url}"/>     <property name="username" value="${db.user}"/>     <property name="password" value="${db.pass}"/> </bean> 

And variables:

hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect hibernate.show_sql=true hibernate.format_sql=true hibernate.hbm2ddl.auto=create 

回答1:

Ok here it is. I am not 100% sure if this helps your case but I think this is what you need to do: Add a jdbc connection to your database from the database tab (usually to your right)


Then add the hibernate facet to your module Go to modules (alt+ctrl+shift+s) then add it:


Now you have enabled the persistance tab on your left (usually) and you can assign a datasource to your

Now add the hibernate configuration but you have to add the xml file of hibernate. I haven't tried it with just adding the spring application context instead of hibernate.cfg.xml. Maybe it will work...


Now you have enable the presistance configuration for intellij and you can assign a datasource to it.


Select that datasource that you want and you will be able to use the JPA console with your jpa POJOs and HSQLs



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!