branaway / play

Play framework
http://www.playframework.org
Other
12 stars 4 forks source link

Some of samples-and-tests script getting JPA issues in jdk8 branch #1

Open senthilboopathi opened 8 years ago

senthilboopathi commented 8 years ago

1. I tried to install jdk8 version and run "forum" sample script, and I tried to register and it gets some Oops error and I click Users link http://localhost:9000/users and getting following error:

JPAQueryException occured : Error while executing query from User: org.hibernate.InstantiationException: No default constructor for entity: models.User

  1. I tried with "multi-db" sample and getting following error.

JPA error A JPA error occurred (Found Entity-class (models.Student) referring to none-existing JPAConfig (jpa config name: default). Is JPA properly configured?):

  1. And I tried my existing application, I got following error:

Compilation error The file /app/libs/modules/config/src/play/modules/config/models/JPAConfigItem.java could not be compiled. Error raised is : Type mismatch: cannot convert from List<capture#1-of ? extends GenericModel> to List

In /app/libs/modules/config/src/play/modules/config/models/JPAConfigItem.java (around line 79) 79: JPAConfigItem> l0 = JPQL.instance.findBy( 80: JPAConfigItem.class.getName(), "order by name", new Object[] {});

Let me know jdk8 branch supports JPA??

Note: Branch: jdk8 https://github.com/branaway/play/tree/jdk8 My java version: java version "1.8.0_25"

Thanks for Advance

rrjanbiah commented 8 years ago

@branaway Can we have your say on this, please? More interested to know your suggestion than your fix.

branaway commented 8 years ago

Sorry I missed your note. I'll take a look at the issue soon.

rrjanbiah commented 8 years ago

@branaway Thanks a lot for your attention.

branaway commented 8 years ago

A couple of things:

  1. I have merged the jdk8 branch to the master and I'm testing the apps from there.
  2. All entities must have a default constructor, required by hibernate. Manually add that to the entity classes.
  3. add gutters and setters to all the entity fields. I have disabled entity enhancement for better performance and the side effect is that you'll need to add them manually if they're required, like in the second example.
  4. the correct way to configure multi-DB in the application.conf is like this:

db_default.url=jdbc:h2:mem:student db_default.driver=org.h2.Driver db_default.user=sa db_default.pass=

db_teacher.url=jdbc:h2:mem:teacher db_teacher.driver=org.h2.Driver db_teacher.user=sa db_teacher.pass=

  1. cannot comment on your app unless you can show me the source code of the JPAConfigItem class.

JPA is supported in general. There might be some quirks. Let me know your use case.

Thanks.

rrjanbiah commented 8 years ago

@branaway Many thanks for your note. On Monday we will provide the source that was having jpa issue. Thanks again

branaway commented 8 years ago

btw, there is issues with the mailer instrumentation, so email sending is not working yet. This would affect the multi-DB sample.

rrjanbiah commented 8 years ago

@branaway Thanks for the note. Will check accordingly.

senthilboopathi commented 8 years ago

@branaway This is the sample code of JPAConfigItem.java

package libs.modules.config.src.play.modules.config.models;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

import play.Logger;
import play.db.jpa.GenericModel;
import play.db.jpa.JPQL;
import play.modules.scaffold.ScaffoldingIgnore;
import libs.modules.config.src.play.modules.config.ConfigPlugin;

/**
 * Default {@link IConfigItem} implementation on JPA
 * 
 */
@Entity
@Table(name = "Conf")
@ScaffoldingIgnore
public class JPAConfigItem extends GenericModel implements IConfigItem {

    /**
     * 
     */
    private static final long serialVersionUID = -8415264008115090076L;

    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public Long id;

    public String name;

    public String value;

    public JPAConfigItem() {
    }

    private JPAConfigItem(String key, String value) {
        this.name = key;
        this.value = value;
    }

    @Override
    public String pc_key() {
        return name;
    }

    @Override
    public String pc_value() {
        return value;
    }

    @Override
    public IConfigItem pc_value(String value) {
        this.value = value;
        return this;
    }

    public IConfigItem pc_save() {
        try{
            return (IConfigItem) save();
        } catch(Exception e){
            e.printStackTrace();
            return (IConfigItem) null;
        }
    }

    @Override
    public String toString() {
        return String.format("%1$s=%2$s", name, value);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<IConfigItem> pc_all() {
        List<IConfigItem> l = new ArrayList<IConfigItem>();
        List<JPAConfigItem> l0 = JPQL.instance.findBy(
                JPAConfigItem.class.getName(), "order by name", new Object[] {});
        for (JPAConfigItem ci : l0) {
            l.add(ci);
        }
        return l;
    }

    @Override
    public IConfigItem pc_new(String key, String value) {
        ConfigPlugin.assertValidKey(key);
        return new JPAConfigItem(key, value);
    }

    @Override
    public IConfigItem pc_findByKey(String key) {
        try {
             Object[] o = new Object[1];
             o[0] = key;
            return (IConfigItem) JPQL.instance.findOneBy(
                    JPAConfigItem.class.getName(), "name", o);
        } catch (Exception e) {
            Logger.warn(e, "Error fetch configuration item by key: %1$s", name);
            return null;
        }
    }

    @Override
    public void pc_clear() {
        JPQL.instance.deleteAll(JPAConfigItem.class.getName());
    }

    @Override
    public void pc_delete() {
        delete();
    }

}
branaway commented 8 years ago

Got that. Since I'm in a hurry, can you test it out with my release in the "releases" menu?

branaway commented 8 years ago

Laptop not handy, but I recommend you put your entity in models package or sub packages. Models must reside in the designated package.

branaway commented 8 years ago

can you try:

    List<JPAConfigItem> fetch = find("order by name", new Object[] {}).fetch();

    // or

    List<JPAConfigItem> findBy = (List<JPAConfigItem>) getJPAConfig(getClass()).jpql.findBy(JPAConfigItem.class.getName(), "order by name", null);

in your own sample code?

senthilboopathi commented 8 years ago

@branaway Thanks for spending time and I tried with

List<JPAConfigItem> fetch = find("order by name", new Object[] {}).fetch();

and its working fine.