2015-11-07 129 views
0

努力嘗試將Spring社交方面實現到Web應用程序中並遇到一些困難。春季 - 社交 - 休眠:無法註冊/登錄UserConnection未映射

我正在使用Postgresql,JPA的Spring Hibernate風格和XML配置的Spring。我找到了一個很好的推薦JAR,這意味着我可以繼續使用JPA。

詳情請看這裏:https://github.com/michaellavelle/spring-social-hibernate-jpa

使用maven進口,其次說明和一切似乎都很好。當與Facebook選擇登錄(我不使用他們的SDK),我收到一個500錯誤:

message org.hibernate.hql.internal.ast.QuerySyntaxException: UserConnection is not mapped [select u from UserConnection u where u.primaryKey.providerId = :providerId and u.primaryKey.providerUserId = :providerUserId order by u.rank] 

description The server encountered an internal error that prevented it from fulfilling this request. 

exception 

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: UserConnection is not mapped [select u from UserConnection u where u.primaryKey.providerId = :providerId and u.primaryKey.providerUserId = :providerUserId order by u.rank] 
    org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1750) 
    org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677) 
    org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683) 
    org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:350) 

錯誤本身似乎相當自我解釋,有在DB沒有UserConnection表這使我想起我錯誤地配置了一些東西,因爲這是圖書館的責任。

還是我完全錯了?非常感謝任何幫助,希望能夠實現這一目標。

編輯: Social.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:facebook="http://www.springframework.org/schema/social/facebook" 
     xmlns:twitter="http://www.springframework.org/schema/social/twitter" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:social="http://www.springframework.org/schema/social" 
     xmlns:linkedin="http://www.springframework.org/schema/social/linkedin" 
     xmlns:c="http://www.springframework.org/schema/c" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/social/facebook 
     http://www.springframework.org/schema/social/spring-social-facebook.xsd 
     http://www.springframework.org/schema/social/linkedin 
     http://www.springframework.org/schema/social/spring-social-linkedin.xsd 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/social/twitter 
     http://www.springframework.org/schema/social/spring-social-twitter.xsd 
     http://www.springframework.org/schema/social 
     http://www.springframework.org/schema/social/spring-social.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/aop 
     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 

<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}" app-namespace="socialshowcase" /> 
<twitter:config app-id="${twitter.consumerKey}" app-secret="${twitter.consumerSecret}"/> 
<linkedin:config app-id="${linkedin.consumerKey}" app-secret="${linkedin.consumerSecret}"/> 

<!--<social:jdbc-connection-repository/>--> 
<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource" /> 

<bean id="connectController" class="org.springframework.social.connect.web.ConnectController" autowire="constructor"> 
    <property name="connectInterceptors"> 
     <list> 
      <bean class="com.simpleSchedule.social.facebook.PostToWallAfterConnectInterceptor" /> 
      <!--<bean class="org.springframework.social.showcase.twitter.TweetAfterConnectInterceptor" />--> 
     </list> 
    </property> 
</bean> 

<bean id="usersConnectionRepository" 
     class="org.springframework.social.connect.jpa.JpaUsersConnectionRepository"> 
    <constructor-arg ref="userConnectionDao" /> 
    <constructor-arg ref="connectionFactoryLocator" /> 
    <constructor-arg ref="textEncryptor" /> 
</bean> 

<bean class="org.springframework.social.connect.jpa.JpaConnectionRepository" 
     id="connectionRepository" factory-method="createConnectionRepository" 
     factory-bean="usersConnectionRepository" scope="request"> 
    <constructor-arg value="#{request.userPrincipal.name}" /> 
    <aop:scoped-proxy proxy-target-class="true" /> 
</bean> 


<bean id="psc" class="org.springframework.social.connect.web.ProviderSignInController" autowire="constructor" /> 
<bean id="signInAdapter" class="com.simpleSchedule.social.singin.SimpleSignInAdapter" autowire="constructor" /> 

<bean id="disconnectController" class="org.springframework.social.facebook.web.DisconnectController" 
    c:_0-ref="usersConnectionRepository" c:_1="${facebook.clientSecret}" /> 

回答

0

邁克爾·拉維爾非常親切地回答了我的評論張貼在gitbub。

解決方案是在我的persistence.xml中添加org.springframework.social.connect.jpa.hibernate.UserConnection作爲映射。

全部細節可查看the github issue