Announcement Announcement Module
Collapse
No announcement yet.
UsersConnectionRepository and ConnectionRepository for JPA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • UsersConnectionRepository and ConnectionRepository for JPA

    Is there any version of UsersConnectionRepository and ConnectionRepository for apps using JPA?

  • #2
    I found this https://github.com/mschipperheyn/spring-social-jpa

    I'm answer my own question in case this is useful for somebody else.

    Comment


    • #3
      You know I thought about going the JPA way too. I mean besides already using Spring Data JPA for some of our data, and the rest using Spring Data other NoSQL projects, that I thought for adding Spring Social it would be nice to keep with that pattern. But after thinking about it, all you have to do for using the already built Jdbc version is run the ddl script to make that one userconnect table and that was it.

      As opposed to doing more work to get jpa. Yes that project makes it easier where you just implement their RemoteUser interface.
      Although that project hasn't been touched in a year. But there aren't many classes to have to constantly be changing it.

      So I guess almost a wash. Nevermind.

      Mark

      Comment


      • #4
        interesting... thing is we're using entitymanagers and such so i don't even have a datasource hanging around.

        Comment


        • #5
          Um, yes you do have a datasource. No other way to get a connection to the database. And EntityManagerFactory which creates EntityManager's need/require a datasource.

          Now you might not be accessing the Datasource yourself directly in your config. It might be that you are running in an App Server that is doing container managed EntityManager with Factory, but that is using a DataSource, a datasource that the App Server creates because of the datasource configuration that comes in the app server, or one that someone at your company defined. If it is the app server's note that the database it is using is probably just a dev temp one and not one that should be used in production.

          And that dataSource an App Server creates is just put into the JNDI tree, just like the EntityManagerFactory was.

          But that is all if you are using an App Server.

          But no matter what there is a DataSource out there that it is using.

          Mark

          Comment


          • #6
            Yes I am running in an App Server that is doing container managed EntityManager with Factory

            here's a snippet of my applicationContext-jpa.xml

            Code:
            	<context:load-time-weaver
            		weaver-class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver" />
            
            	<bean id="pum"
            		class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
            		<property name="persistenceXmlLocations">
            			<list>
            				<value>classpath*:META-INF/persistence.xml</value>
            			</list>
            		</property>
            	</bean>
            
            	<bean id="emf"
            		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            		<property name="persistenceUnitManager" ref="pum" />
            		<property name="persistenceUnitName" value="BLABLABLA" />
            	</bean>

            Comment


            • #7
              In short: There is currently not a JPA implementation of the connection repositories, aside from some work that has been done in the community.

              And, to be honest, I struggle a bit understanding why one is necessary when the JDBC-based one will work fine. The only piece of code that cares about connections is the connection repository and therefore it's not like *you're* code will be reading/writing to the connection table. And that table has no joins with other tables. For all intents and purposes, it could be in a completely different database (although it's handy having it in the same database for DataSource-reuse purposes). So why is a JPA-specific implementation needed?

              Comment


              • #8
                I agree that a JPA isn't needed. I am big on JPA and rarely use Jdbc. Mostly use Jdbc to test out my JPA code.

                But I choose to use the built in jdbcConnectionRepository because it was the least amount of work. Just create the table in the database.

                I can see, as Yuan did building a new implementation if you are using NoSQL and don't have an RDBMS in your application.

                Mark

                Comment


                • #9
                  Fine. Then I guess my issue is on getting a dataSource out of the configuration we're currently using (see my previous post)

                  Comment


                  • #10
                    My guess is look in your persistence.xml file. Somewhere you have to connect your EntityManagerFactory to a datasource, and in this case it should show in that file.

                    Or, I haven't used Glassfish, but how does it define and configure a datasource, and find that file to find the name.

                    If you need it to be a bean, then you can do a jndi lookup in your configuration with

                    <jee:jndi-lookup> tag.

                    Mark

                    Comment

                    Working...
                    X