Hi,

I am trying to setup jooq for the first time. I have a sample application 
wherein I am trying to connect to a db having a table Posts in the database 
guestbook. PFA the generated  java file for this table and below is the sql 
I used to create this table.

mysql> use guestbook;
Database changed

mysql> CREATE TABLE `posts` (
    ->   `id` bigint(20) NOT NULL,
    ->   `body` varchar(255) DEFAULT NULL,
    ->   `timestamp` datetime DEFAULT NULL,
    ->   `title` varchar(255) DEFAULT NULL,
    ->   PRIMARY KEY (`id`)
    -> );
Query OK, 0 rows affected (1.34 sec)

I used the following command to generate the tables :

c:\Ankita\temp>java -classpath 
jooq-3.6.2.jar;jooq-meta-3.6.2.jar;jooq-codegen-3.6.2.jar;mysql-connector-java-5.1.35-bin.jar;.
 
org.jooq.util.GenerationTool /jooq.xml

Also, PFA my xml file.

The problem I am facing is when I am trying to reference the ID field of 
Posts class in java in my app, like this :

Long id = r.getValueAsLong(Posts.ID);

It gives an error 
Description Resource Path Location Type
Cannot make a static reference to the non-static field Posts.ID   
 JooqMainApp.java /JooQSample/src line 32 Java Problem

That is right because ID field is not static in the generate Posts.java 
class. How should I fix it in this case?

While I was reading on this further, I read somewhere that instanceFields 
property in code generator config might help on this. But seems its 
deprecated as of jOOQ 3.3.0.

Any help on this would be very much appreciated.

Thanks in advance!

Regards,
Ankita




-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
/**
 * This class is generated by jOOQ
 */
package test.generated.tables;


import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Generated;

import org.jooq.Field;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.UniqueKey;
import org.jooq.impl.TableImpl;

import test.generated.Guestbook;
import test.generated.Keys;
import test.generated.tables.records.PostsRecord;


/**
 * This class is generated by jOOQ.
 */
@Generated(
	value = {
		"http://www.jooq.org";,
		"jOOQ version:3.6.2"
	},
	comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Posts extends TableImpl<PostsRecord> {

	private static final long serialVersionUID = 1433123087;

	/**
	 * The reference instance of <code>guestbook.posts</code>
	 */
	public static final Posts POSTS = new Posts();

	/**
	 * The class holding records for this type
	 */
	@Override
	public Class<PostsRecord> getRecordType() {
		return PostsRecord.class;
	}

	/**
	 * The column <code>guestbook.posts.id</code>.
	 */
	public final TableField<PostsRecord, Long> ID = createField("id", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, "");

	/**
	 * The column <code>guestbook.posts.body</code>.
	 */
	public final TableField<PostsRecord, String> BODY = createField("body", org.jooq.impl.SQLDataType.VARCHAR.length(255), this, "");

	/**
	 * The column <code>guestbook.posts.timestamp</code>.
	 */
	public final TableField<PostsRecord, Timestamp> TIMESTAMP = createField("timestamp", org.jooq.impl.SQLDataType.TIMESTAMP, this, "");

	/**
	 * The column <code>guestbook.posts.title</code>.
	 */
	public final TableField<PostsRecord, String> TITLE = createField("title", org.jooq.impl.SQLDataType.VARCHAR.length(255), this, "");

	/**
	 * Create a <code>guestbook.posts</code> table reference
	 */
	public Posts() {
		this("posts", null);
	}

	/**
	 * Create an aliased <code>guestbook.posts</code> table reference
	 */
	public Posts(String alias) {
		this(alias, POSTS);
	}

	private Posts(String alias, Table<PostsRecord> aliased) {
		this(alias, aliased, null);
	}

	private Posts(String alias, Table<PostsRecord> aliased, Field<?>[] parameters) {
		super(alias, Guestbook.GUESTBOOK, aliased, parameters, "");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public UniqueKey<PostsRecord> getPrimaryKey() {
		return Keys.KEY_POSTS_PRIMARY;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<UniqueKey<PostsRecord>> getKeys() {
		return Arrays.<UniqueKey<PostsRecord>>asList(Keys.KEY_POSTS_PRIMARY);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Posts as(String alias) {
		return new Posts(alias, this);
	}

	/**
	 * Rename this table
	 */
	public Posts rename(String name) {
		return new Posts(name, null);
	}
}

Attachment: jooq.xml
Description: XML document

Reply via email to