Hi,
no, I'm not running the example application. Well, I've decided to
write a minimalistic howto on start using Ebean, please have a look
at
http://alxa.wikidot.com/ebean-howto-1 for the complete setup.
Below the main code:
public class HelloWorld {
public static void main(String[] args) {
// ### Configuration Objects ###
ServerConfig serverConfig = new ServerConfig();
DataSourceConfig dataSourceConfig = new DataSourceConfig();
// ### Configuration Settings ###
// -> data source
dataSourceConfig.setDriver("org.h2.Driver");
dataSourceConfig.setUsername("howtouser");
dataSourceConfig.setPassword("");
dataSourceConfig.setUrl("jdbc:h2:db/howto1");
// -> server
serverConfig.setName("default");
serverConfig.setDataSourceConfig(dataSourceConfig);
// auto create db if it does not exist
if(!(new File("db/howto1.h2.db")).exists() ){
serverConfig.setDdlGenerate(true);
serverConfig.setDdlRun(true);
serverConfig.addClass(Hello.class);
}
EbeanServer eServer = EbeanServerFactory.create(serverConfig);
long id = 3;
Hello data = eServer.find(Hello.class, id);
if (data == null) {
System.out.println("This is the first run, saving
data..");
eServer.save(new Hello(id, "Hello World!"));
} else {
System.out.println(String.format("############\n%s
\n############", data.getMessage()));
}
ShutdownManager.shutdown();
}
}
Thanks in advance
alx
On 18 Okt., 02:50, Rob Bygrave <
robin.bygr...@gmail.com> wrote:
> When running the example application you should not need to shutdown H2.
>
> It's actually not clear to me what you are doing and what your issue is ...
> but I'll guess and say you are running the example application ... one of
> the classes with a main method... and it is hanging / not terminating?
>
> I haven't come across any problem like that... is this your issue or am I
> misunderstanding?
>
> Note that Ebean registers with the JVM shutdown hook ... and uses that to
> close it's resources such as thread pools and Connection pools. It also can
> trigger a GC to collection profiling information for Autofetch (with a small
> wait of 100ms from memory).
>
> Thanks, Rob.
>