liefke / org.fastnate

The Offline SQL Generator
Apache License 2.0
16 stars 11 forks source link

Cannot instantiate the type EntitySqlGenerator #31

Closed abhiramikl closed 6 years ago

abhiramikl commented 6 years ago

EntitySqlGenerator e = new EntitySqlGenerator(this.context); e.write(courseEntity); When creating an object of EntitySqlGenerator this error comes

"Cannot instantiate the type EntitySqlGenerator"

How can I solve it?

liefke commented 6 years ago

What the Java compiler is trying to say: There is no EntitySqlGenerator constructor with just the context. The generator needs always a Writer as parameter, which is used as target of the generated statements.

abhiramikl commented 6 years ago

How will I initialize Writer, I tried but giving some error.

liefke commented 6 years ago

It depends on your purpose: Where do you want to write the SQL statements? To a file or to a string? Either use a FileWriter or a StringWriter.

abhiramikl commented 6 years ago

I need insert query of an entity class in a string.

liefke commented 6 years ago

The EntitySqlGenerator is not for generating queries, it is for generating insert statements. That having said, here is an example how you could do that:

StringWriter writer = new StringWriter();
EntitySqlGenerator generator = new WriterEntitySqlGenerator(writer, context);
generator.write(myEntity);
String sql = writer.toString();

This example is for Fastnate 1.3 - in the upcoming version 1.4 the class structure has changed a little bit - but the concept is the same.

abhiramikl commented 6 years ago

Hallo, Still same issue occurs when i try this code also.Code is given below: StringWriter writer = new StringWriter(); EntitySqlGenerator e = new EntitySqlGenerator(writer , this.context); e.write(courseRecords);

liefke commented 6 years ago

You have to use a WriterEntitySqlGenerator in Fastnate 1.3.

abhiramikl commented 6 years ago

I'm using fastnate1.3.0, when calling WriterEntitySqlGenerator this error is throwing :

nested exception is java.lang.UnsupportedClassVersionError: org/fastnate/generator/WriterEntitySqlGenerator : Unsupported major.minor version 52.0 (unable to load class org.fastnate.generator.WriterEntitySqlGenerator)] with root cause java.lang.UnsupportedClassVersionError: org/fastnate/generator/WriterEntitySqlGenerator : Unsupported major.minor version 52.0 (unable to load class org.fastnate.generator.WriterEntitySqlGenerator)

liefke commented 6 years ago

It seems that you are developing or testing with Java 7. As Fastnate 1.3.0 was compiled with Java 8, you will have to switch to either Java 8 or Java 9.

abhiramikl commented 6 years ago

Hai, Fastnate1.2 also doesn't support with Java 7. My development environment works only in java 7. Can u suggest which version will support with Java

  1. My requirement is I need insert query if an entity class. Please help me.

On Wed 28 Feb, 2018 3:06 am Tobias Liefke, notifications@github.com wrote:

It seems that you are developing or testing with Java 7. As Fastnate 1.3.0 was compiled with Java 8, you will have to switch to either Java 8 or Java 9.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/liefke/org.fastnate/issues/31#issuecomment-369034568, or mute the thread https://github.com/notifications/unsubscribe-auth/APkwt1sMVNsS0PCk00WXK-NTx7C1iBTAks5tZHVTgaJpZM4SQX6d .

liefke commented 6 years ago

As you can see here, the last version that supported Java 1.7 was 1.0.0-RC1. But that version was never published to Maven-Central. It is still available from our binary repository, which you can access as defined in our download section (look for snapshot builds).

As the RC1 indicates, that version had still some bugs - I hope you can use it nevertheless.