Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate integration #3

Open
n0ct opened this issue Sep 21, 2021 · 8 comments
Open

Hibernate integration #3

n0ct opened this issue Sep 21, 2021 · 8 comments

Comments

@n0ct
Copy link

n0ct commented Sep 21, 2021

Hello,
I would like to integrate this project into a gradle hibernate project.

  • Can I include (and shade this project) as a library ? In other words is it published on a nexus/artifactory or should I simply include the code in a git submodule ?
  • About its usage, should I follow what was explained on https://code.google.com/archive/p/hibernate-generic-dao/ and make my DAO extends GenericDAO and GenericDAOImpl or should I do something else ?

Thank you for your work !

@n0ct
Copy link
Author

n0ct commented Sep 21, 2021

About my second question :
After looking at the code it indeed seems implementing GenericDAO and extending GenericDAOImpl is the only option. Sorry for the irrelevant question.

@mohsen
Copy link
Owner

mohsen commented Sep 21, 2021

  • Can I include (and shade this project) as a library ? In other words is it published on a nexus/artifactory or should I simply include the code in a git submodule ?

A version from the original author is available on maven:
https://mvnrepository.com/artifact/com.googlecode.genericdao/dao

The version provided here on github has a few bug fixes and some new features, but is not submitted to maven. We use it on a private nexus server.

@n0ct
Copy link
Author

n0ct commented Sep 22, 2021

Would you mind publishing this project on a public nexus? I guess you have other things to do then, if you prefer, I'd be willing to try to do it for you ? Even if I'm more used to gradle/artifactory/gitlab than maven/nexus/github I think I can help you with that.

@n0ct
Copy link
Author

n0ct commented Sep 22, 2021

Until then, I forked the project and published on my own private artifactory.

Small questions:

  • Which dependency should I import in maven/gradle: All non-test jars or only some of them ?
  • Which GenericDAO should I implement ? (I use hibernate but not sping)
    • genericdao.dao.hibernate.GenericDAO
    • genericdao.dao.jpa
    • genericdao.dao.hibernate.original.GenericDAO
  • Same question for GenericDAOImpl ?

Thank you per advance. And thank you again for all this work on the bugfixes / new features.

@n0ct
Copy link
Author

n0ct commented Sep 22, 2021

I tried by importing only dao-hibernate and by using genericdao.dao.hibernate.GenericDAO.

It seems globally ok. Here is my project's abstract DAO:

package fr.skytale.databaselib.database.parent;

import com.googlecode.genericdao.dao.hibernate.GenericDAO;
import com.googlecode.genericdao.dao.hibernate.GenericDAOImpl;
import fr.skytale.databaselib.DatabaseLib;
import org.hibernate.SessionFactory;

import java.io.Serializable;

public abstract class ADAO<T, ID extends Serializable> extends GenericDAOImpl<T, ID> implements GenericDAO<T, ID> {
    protected final DatabaseLib databaseLib;

    public ADAO(DatabaseLib databaseLib) {
        this.databaseLib = databaseLib;
        final SessionFactory sessionFactory = databaseLib.getSessionFactory();
        setSessionFactory(sessionFactory);
    }
}

If you see any issue in this way of using this project please tell me.

Thank you anyway.

@mohsen
Copy link
Owner

mohsen commented Sep 22, 2021

  1. I appreciate if you can take and maintain the project. I didn't submit any project yet to maven. But I can help if you take the job,
  2. We extend GenericDAOImpl in our project (JPA/Hibernate/Spring). @transactional is added to methods (or can be added to the extended class).
  3. I didn't use it on a pure hibernate scenario, so cannot help here.
  4. In a Spring scenario the following beans should be initialized:
     <bean id="metadataUtil" class="com.googlecode.genericdao.search.jpa.JPAAnnotationMetadataUtil" />
    <bean id="searchProcessor" class="com.googlecode.genericdao.search.jpa.JPASearchProcessor">
        <constructor-arg ref="metadataUtil" />
    </bean>

@n0ct
Copy link
Author

n0ct commented Sep 30, 2021

I don't managed to make it work without spring yet. I will keep you posted.

@n0ct
Copy link
Author

n0ct commented Oct 4, 2021

I managed to make it work but I had to manually implement transaction management.
I also did not test every features so I'm unsure JPASearchProcessor works yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants