MySQL, JPA with Play! Framework

602 views
Skip to first unread message

Cwellan

unread,
Apr 2, 2012, 3:16:14 PM4/2/12
to play-fr...@googlegroups.com
Hi,

First, sorry for my bad language, i'm french...

I have a database MySQL with a lot of tables filled.
I want that play detect automatically the tables of MySQL and create the models on play. Is it possible ?
I know that i can create automatically the table on MySQL with the models of Play and i can rule that with the line : %test.jpa.ddl=create/update/...


Thanks in advance.

Best regards.

Nicolas Leroux

unread,
Apr 2, 2012, 4:05:45 PM4/2/12
to play-fr...@googlegroups.com
You can try the following module:

http://www.playframework.org/modules/db

Nicolas

2012/4/2 Cwellan <leo.rai...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/z_Q-_ku5BlgJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

--
Nicolas Leroux

Tom Carchrae

unread,
Apr 2, 2012, 4:08:03 PM4/2/12
to play-fr...@googlegroups.com
Maybe that module will work for you, but it did not work for me when I tried it with Play 1.2.3 and 1.2.4.

You can also use EclipseLink or HibernateTools to generate JPA entities from database tables. 

Tom



On Mon, Apr 2, 2012 at 1:05 PM, Nicolas Leroux <leroux....@gmail.com> wrote:
You can try the following module:

Cwellan

unread,
Apr 2, 2012, 4:24:02 PM4/2/12
to play-fr...@googlegroups.com
Thanks a lot for your answer. I'll try.

Cwellan

unread,
Apr 2, 2012, 6:18:11 PM4/2/12
to play-fr...@googlegroups.com
Hi,

I encountered an error:

Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.mapping.SimpleValue.<init>(Lorg/hibernate/mapping/Table;)V
 at org.hibernate.cfg.JDBCBinder.bindColumnToSimpleValue(JDBCBinder.java:589)
 at org.hibernate.cfg.JDBCBinder.bindPrimaryKeyToProperties(JDBCBinder.java:443)
 at org.hibernate.cfg.JDBCBinder.createPersistentClasses(JDBCBinder.java:174)
 at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:91)
 at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:40)
 at play.modules.db.Importer.main(Importer.java:164)

Do you know what it is ?

Thanks in advance.


Le lundi 2 avril 2012 22:05:45 UTC+2, Nicolas Leroux - committer a écrit :
You can try the following module:

http://www.playframework.org/modules/db

Nicolas

2012/4/2 Cwellan:


> Hi,
>
> First, sorry for my bad language, i'm french...
>
> I have a database MySQL with a lot of tables filled.
> I want that play detect automatically the tables of MySQL and create the
> models on play. Is it possible ?
> I know that i can create automatically the table on MySQL with the models of
> Play and i can rule that with the line : %test.jpa.ddl=create/update/...
>
>
> Thanks in advance.
>
> Best regards.
>
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/z_Q-_ku5BlgJ.

> To post to this group, send email to play-framework@googlegroups.com.


> To unsubscribe from this group, send email to

> play-framework+unsubscribe@googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

--
Nicolas Leroux

Tom Carchrae

unread,
Apr 2, 2012, 6:29:13 PM4/2/12
to play-fr...@googlegroups.com
If you switch back to Play 1.1.1 (last tested version) I think it will work.

That is the same error I came across when using with 1.2.4

Tom

To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/uLxNC-0VYq0J.

To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

Stéphane Blondel

unread,
Apr 2, 2012, 6:35:06 PM4/2/12
to play-fr...@googlegroups.com
Hi, I'm Cwellan's friendship, 
I work with him and I read somewhere that It's  possible to downgrade Hibernate to resolve this error. 
But I don't think so if it's a good idea :s

Thanks a lot tom :)

Jaime Hablutzel Egoavil

unread,
Apr 2, 2012, 6:48:21 PM4/2/12
to play-fr...@googlegroups.com
IntelliJ IDEA can generate object model for your DDL too
--
Jaime Hablutzel - 9-9956-3299
 
(tildes omitidas intencionalmente)

Cwellan

unread,
Apr 2, 2012, 7:30:55 PM4/2/12
to play-fr...@googlegroups.com
I'm sorry but i don't know how it works...
If you have any others solutions with play it will be better, sorry...

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.



--

Cwellan

unread,
Apr 3, 2012, 3:50:22 AM4/3/12
to play-fr...@googlegroups.com
Hi all,

I tested with the db module: the bug is provoked by the foreign keys on the tables.
I don't know how to fix it.

Best regards.


Le lundi 2 avril 2012 21:16:14 UTC+2, Cwellan a écrit :

Tom Carchrae

unread,
Apr 3, 2012, 10:27:13 AM4/3/12
to play-fr...@googlegroups.com
If your database is stable, you can generate the Entities once using EclipseLink or HibernateTools, then edit them to work with Play (you probably want to extend play.db.GenericModel).  I have done this in the past.  

Once you have your JPA POJOs, you don't need these tools anymore and can use whatever version of Play you like.  Of course, you need to repeat this process each time the DB schema changes - so that is the pain.  But if your database changes and your Play project uses those fields, you are in trouble anyway. 

If you use EclipseEE, create a JPA Project, there is an option "JPA Tools -> Generate Entities from Tables"

It is some work to set up EclipseLink or any of these tools, but not too difficult.

At the end of the day, though, you must ask yourself if that was quicker than the tedious/boring task of creating by hand the JPA classes you needed.  :)

Tom







To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/5TtXq60cDuoJ.

To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

Cwellan

unread,
Apr 17, 2012, 7:45:55 AM4/17/12
to play-fr...@googlegroups.com
Hi,

I found a solution but i don't know how to apply it... Anyone can help me ?

The link: https://github.com/pepite/play--database/issues/7

Anyone can make the package for me please ?

The text of the solution is:
_________________________________________________________

Hi All,

I resolved this issue for play-1.2.2

1, fixed hibernate-tools JavaTypeFromValueVisitor.java 's method as follow:
public Object accept(OneToMany value) {
//return value.getAssociatedClass().getClassName();
return value.getReferencedEntityName();
}

2, copy hibernate3.jar to module/db-1.1.1/lib

that's it, works for me.

_________________________________________________________


Best Regards.


Le lundi 2 avril 2012 21:16:14 UTC+2, Cwellan a écrit :
Le lundi 2 avril 2012 21:16:14 UTC+2, Cwellan a écrit :

Cwellan

unread,
Apr 18, 2012, 4:06:27 AM4/18/12
to play-fr...@googlegroups.com
Up !


Le lundi 2 avril 2012 21:16:14 UTC+2, Cwellan a écrit :

Cwellan

unread,
Apr 24, 2012, 4:38:53 AM4/24/12
to play-fr...@googlegroups.com
Thanks for your answer.


The main problem is that we will change de database schema more than one time a month.
So if we can fix this problem, this will be very interesting. We found why the error occurs, and if we can fix it, we will share the solution with everyone !

I think you're right, saying we lose too much time, but if we can make it works, it will be very interesting !

Best regards.


Cwellan

unread,
Apr 26, 2012, 2:45:47 AM4/26/12
to play-fr...@googlegroups.com
Hi all,

I succeed in making it works... Thanks to Dsheng !

Here is a modification of the module db: http://depositfiles.com/files/vyxhraamy .

You can also see : https://github.com/pepite/play--database and adapt the package.


Best regards.

Tom Carchrae

unread,
Apr 26, 2012, 8:48:14 AM4/26/12
to play-fr...@googlegroups.com
great stuff.

dear keepers of play 1.2.4 - we really need to roll these changes in
to some of the old modules. this seems to happen sometimes, that
modules get abandoned and then there is no one to update them anymore.
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/tcMvlbg-WVwJ.
Reply all
Reply to author
Forward
0 new messages