JOOQ:没有加载任何模式吗? - java

我正在尝试通过在项目中使用JOOQ来学习它。

这是我的实体

@Entity
public class User {
    @Id
    private String id;
    private String userExternalId;
    @Column(unique = true)
    private String email;
    private String clientId;
    private String clientSecret;
    private boolean active;

    public User(@Nonnull final String userExternalId, @Nonnull final String email,
                @Nonnull final String clientId, @Nonnull final String clientSecret) {
        id = UUID.randomUUID().toString();
        this.userExternalId = userExternalId;
        this.email = email;
        this.clientId = clientId;
        this.clientSecret = clientSecret;
        active = true;
    }

    public User() {
    }

    @Nonnull
    public String getId() {
        return id;
    }

    @Nonnull
    public String getUserExternalId() {
        return userExternalId;
    }

    @Nonnull
    public String getEmail() {
        return email;
    }

    @Nonnull
    public String getClientId() {
        return clientId;
    }

    @Nonnull
    public String getClientSecret() {
        return clientSecret;
    }

    public boolean isActive() {
        return active;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", externalUserId='" + userExternalId + '\'' +
                ", email='" + email + '\'' +
                ", clientId='" + clientId + '\'' +
                ", clientSecret='" + clientSecret + '\'' +
                ", active=" + active +
                '}';
    }
}

这是UserService

public class UserService {
    private final EntityManager entityManager;

    public UserService(@Nonnull final EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    @Nonnull
    public User createUser(@Nonnull final User user) {
        entityManager.persist(user);
        return user;
    }
}  

我的persistence/pom.xml看起来像

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>oauth</artifactId>
        <groupId>com.self</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>persistence</artifactId>
    <name>OAuth: Persistence</name>

    <properties>
        <hibernate-jpa-2.0-api.version>1.0.1.Final</hibernate-jpa-2.0-api.version>
        <junit.version>4.11</junit.version>
        <hibernate-entitymanager.version>4.3.6.Final</hibernate-entitymanager.version>
        <h2.version>1.4.180</h2.version>
        <querydsl-version>3.4.2</querydsl-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>${hibernate-jpa-2.0-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-entitymanager.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${h2.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- Specify the maven code generator plugin -->
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <version>3.4.1</version>

                <!-- The plugin should hook into the generate goal -->
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>

                <!-- Manage the plugin's dependency. In this example, we'll use a H2 database -->
                <dependencies>
                    <dependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                        <version>${h2.version}</version>
                    </dependency>
                </dependencies>

                <!-- Specify the plugin configuration.
                     The configuration format is the same as for the standalone code generator -->
                <configuration>
                    <!-- JDBC connection parameters -->
                    <jdbc>
                        <driver>org.h2.Driver</driver>
                        <url>jdbc:h2:mem:oauth</url>
                        <user>sa</user>
                        <password></password>
                    </jdbc>

                    <!-- Generator parameters -->
                    <generator>
                        <name>org.jooq.util.DefaultGenerator</name>
                        <database>
                            <name>org.jooq.util.h2.H2Database</name>
                            <includes>.*</includes>
                            <excludes></excludes>
                            <inputSchema>public</inputSchema>
                        </database>
                        <target>
                            <packageName>com.self.oauth.persistence.entities</packageName>
                            <directory>target/generated-sources/jooq</directory>
                        </target>
                    </generator>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

当我运行mvn -pl persistence时,日志看起来像

➜  oauth git:(master) ✗ mvn -pl persistence
[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] 'usePluginRegistry' is deprecated and has no effect. @ /Users/harith/.m2/settings.xml
[WARNING] 
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building OAuth: Persistence 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ persistence ---
[INFO] Deleting /Users/harith/code/IdeaProjects/others/oauth/persistence/target
[INFO] 
[INFO] --- jooq-codegen-maven:3.4.1:generate (default) @ persistence ---
[INFO] Using this configuration:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.4.0.xsd">
    <jdbc>
        <driver>org.h2.Driver</driver>
        <url>jdbc:h2:mem:oauth</url>
        <user>sa</user>
    </jdbc>
    <generator>
        <name>org.jooq.util.DefaultGenerator</name>
        <database>
            <name>org.jooq.util.h2.H2Database</name>
            <includes>.*</includes>
            <excludes></excludes>
            <includeExcludeColumns>false</includeExcludeColumns>
            <recordVersionFields></recordVersionFields>
            <recordTimestampFields></recordTimestampFields>
            <syntheticPrimaryKeys></syntheticPrimaryKeys>
            <overridePrimaryKeys></overridePrimaryKeys>
            <dateAsTimestamp>false</dateAsTimestamp>
            <unsignedTypes>true</unsignedTypes>
            <inputSchema>public</inputSchema>
            <outputSchemaToDefault>false</outputSchemaToDefault>
        </database>
        <target>
            <packageName>com.self.oauth.persistence.entities</packageName>
            <directory>/Users/harith/code/IdeaProjects/others/oauth/persistence/target/generated-sources/jooq</directory>
        </target>
    </generator>
</configuration>

[INFO] License parameters       
[INFO] ----------------------------------------------------------
[INFO]   Thank you for using jOOQ and jOOQ's code generator
[INFO]                          
[INFO] Database parameters      
[INFO] ----------------------------------------------------------
[INFO]   dialect                : H2
[INFO]   URL                    : jdbc:h2:mem:oauth
[INFO]   target dir             : /Users/harith/code/IdeaProjects/others/oauth/persistence/target/generated-sources/jooq
[INFO]   target package         : com.self.oauth.persistence.entities
[INFO]   includes               : [.*]
[INFO]   excludes               : []
[INFO]   includeExcludeColumns  : false
[INFO] ----------------------------------------------------------
[INFO]                          
[INFO] DefaultGenerator parameters
[INFO] ----------------------------------------------------------
[INFO]   strategy               : class org.jooq.util.DefaultGeneratorStrategy
[INFO]   deprecated             : true
[INFO]   generated annotation   : true
[INFO]   JPA annotations        : false
[INFO]   validation annotations : false
[INFO]   instance fields        : true
[INFO]   records                : true
[INFO]   pojos                  : false
[INFO]   immutable pojos        : false
[INFO]   interfaces             : false
[INFO]   daos                   : false
[INFO]   relations              : true
[INFO]   global references      : true
[INFO] ----------------------------------------------------------
[INFO]                          
[INFO] Generation remarks       
[INFO] ----------------------------------------------------------
[INFO]   none                   
[INFO]                          
[INFO] ----------------------------------------------------------
[INFO] Emptying                 : /Users/harith/code/IdeaProjects/others/oauth/persistence/target/generated-sources/jooq/com/self/oauth/persistence/entities
[WARNING] No schemata were loaded  : Please check your connection settings, and whether your database (and your database version!) is really supported by jOOQ. Also, check the case-sensitivity in your configured <inputSchema/> elements : [public]
[INFO] Generating schemata      : Total: 0
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ persistence ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ persistence ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /Users/harith/code/IdeaProjects/others/oauth/persistence/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ persistence ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ persistence ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/harith/code/IdeaProjects/others/oauth/persistence/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ persistence ---
[INFO] Surefire report directory: /Users/harith/code/IdeaProjects/others/oauth/persistence/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.self.oauth.persistence.entities.UserServiceTest
Aug 09, 2014 9:28:15 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 09, 2014 9:28:15 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 09, 2014 9:28:15 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 09, 2014 9:28:15 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: oauthTest
    ...]
Aug 09, 2014 9:28:15 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.6.Final}
Aug 09, 2014 9:28:15 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 09, 2014 9:28:15 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 09, 2014 9:28:15 AM org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl processProperties
WARN: HHH000059: Defining hibernate.transaction.flush_before_completion=true ignored in HEM
Aug 09, 2014 9:28:15 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Aug 09, 2014 9:28:15 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Aug 09, 2014 9:28:15 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [org.h2.Driver] at URL [jdbc:h2:mem:oauth]
Aug 09, 2014 9:28:15 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=sa, password=****}
Aug 09, 2014 9:28:15 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Aug 09, 2014 9:28:15 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Aug 09, 2014 9:28:15 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Aug 09, 2014 9:28:15 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: User
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: User
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: User
Aug 09, 2014 9:28:15 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: 
    insert 
    into
        User
        (active, clientId, clientSecret, email, userExternalId, id) 
    values
        (?, ?, ?, ?, ?, ?)
Aug 09, 2014 9:28:16 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 09, 2014 9:28:16 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 09, 2014 9:28:16 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 09, 2014 9:28:16 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: oauthTest
    ...]
Aug 09, 2014 9:28:16 AM org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl processProperties
WARN: HHH000059: Defining hibernate.transaction.flush_before_completion=true ignored in HEM
Aug 09, 2014 9:28:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Aug 09, 2014 9:28:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [org.h2.Driver] at URL [jdbc:h2:mem:oauth]
Aug 09, 2014 9:28:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=sa, password=****}
Aug 09, 2014 9:28:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Aug 09, 2014 9:28:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Aug 09, 2014 9:28:16 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Aug 09, 2014 9:28:16 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: OAUTH.PUBLIC.USER
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [clientid, clientsecret, userexternalid, active, id, email]
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary_key_2, uk_e6gkqunxajvyxl5uctpl2vl2p_index_2]
Aug 09, 2014 9:28:16 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Aug 09, 2014 9:28:16 AM org.hibernate.jpa.internal.EntityManagerFactoryRegistry addEntityManagerFactory
WARN: HHH000436: Entity manager factory name (oauthTest) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
Hibernate: 
    insert 
    into
        User
        (active, clientId, clientSecret, email, userExternalId, id) 
    values
        (?, ?, ?, ?, ?, ?)
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.112 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ persistence ---
[INFO] Building jar: /Users/harith/code/IdeaProjects/others/oauth/persistence/target/persistence-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-sortpom-plugin:2.3.0:sort (default) @ persistence ---
[INFO] Sorting file /Users/harith/code/IdeaProjects/others/oauth/persistence/pom.xml
[INFO] Pom file is already sorted, exiting
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ persistence ---
[INFO] Installing /Users/harith/code/IdeaProjects/others/oauth/persistence/target/persistence-1.0-SNAPSHOT.jar to /Users/harith/.m2/repository/com/self/persistence/1.0-SNAPSHOT/persistence-1.0-SNAPSHOT.jar
[INFO] Installing /Users/harith/code/IdeaProjects/others/oauth/persistence/pom.xml to /Users/harith/.m2/repository/com/self/persistence/1.0-SNAPSHOT/persistence-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.892 s
[INFO] Finished at: 2014-08-09T09:28:16-08:00
[INFO] Final Memory: 19M/84M
[INFO] ------------------------------------------------------------------------  

问题

为什么来源不是JOOQ生成的?我想念什么?

附言我正在使用Java 1.8

参考方案

您正在使用以下H2 JDBC URL:

jdbc:h2:mem:oauth

根据H2 database docs,这意味着不会保留任何数据:

对于某些用例(例如:快速原型制作,测试,高性能操作,只读数据库),可能不需要保留数据或保留对数据的更改。该数据库支持内存模式,在该模式下数据不会持久保存。

在您的Maven插件的连续运行之间,数据库很可能没有持久化。

除此之外,从Maven日志输出中,似乎jOOQ代码生成器在Hibernate的hbm2dll工具之前运行。

一种解决方法(但也许不是一个好的解决方案)是使用H2的基于文件的"embedded connection":

jdbc:h2:~/test

45码

Java中的<<或>>>是什么意思? - java

This question already has answers here: Closed 7 years ago. Possible Duplicate: What does >> and >>> mean in Java?我在一些Java代码中遇到了一些陌生的符号,尽管代码可以正确编译和运行,但对于括号在此代码中的作用却感…

菱形运算符<>是否等于<?> - java

我在util.TreeSet类中发现,其中一个构造函数正在使用具有空泛型类型的新TreeMap调用另一个构造函数。 public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<>(comparator)); } new TreeMap<>是什么意思…

Java:我可以在Hashmaps中使用数组吗? - java

我可以在Hashmaps中使用数组吗?如果是这样,则声明这种哈希图的确切语法是什么?谢谢 参考方案 数组也是对象。甚至像int[]这样的原始数组。Map<String,String[]> map = new HashMap<String,String[]>();

休眠映射<键,设置<值>> - java

我有以下表格:@Entity @Table(name = "events") Event --id --name @Entity @Table(name = "state") State --id --name @Entity @Table(name = "action") Action --id …

无法从ArrayList <String>转换为List <Comparable> - java

当我写下面的代码时,编译器说 无法从ArrayList<String>转换为List<Comparable>private List<Comparable> get(){ return new ArrayList<String>(); } 但是当我用通配符编写返回类型时,代码会编译。private List&l…