Thursday, October 17, 2013

Maven: Generating DDL Scripts from JPA Annotations

Java’s persistence API (JPA) makes object-relational mapping very convenient. Persistence providers like Hibernate can create tables and sequences automatically saving lots of tedious work at development time. However, in production systems automatic schema creation isn’t desired.
In many cases you want to tune the schema a bit, like adding an index for speeding up common access paths, renaming constraints and the like. Additionally, an application should run with as little DB privileges as possible, so it’s quite common that CREATE TABLE or other DDL/SQL statements are simply not permitted.
That’s where the Hibernate3 Maven Plugin can give you a good starting point for your optimizations.

Prerequisites

This article is for you if
  • you use JPA annotations on your entities
  • your persistence provider is Hibernate 3

Configuration

The plugin wraps an Ant task from Hibernate Tools that analyzes your JPA entities and creates a database schema for them.
Add the following to your pom.xml:


hibernate3-maven-plugin 2.2 hbm2ddl jpaconfiguration Default schema.ddl false true false true
Then adjust your persistence.xml file in src/main/resources/META-INF to set the SQL dialect to use for the DDL statements:



The example above uses HSQL (the embedded database that ships with JBoss), but you’ll likely need a different dialect for your production setup. You can get a list of supported dialects from Hibernate’s API documentation. Also make sure that the persistence unit’s name (Default in this example) matches with the plugin configuration and your persistence.xml.
Now execute the hbm2ddl goal from the command line to create the schema:
mvn hibernate3:hbm2ddl
You will find your schema in target/hibernate3/sql/schema.ddl.

Alternatives

If you want to execute hibernate3::hbm2ddl automatically as part of your normal build, you can tie the hbm2ddl goal to the process-classes phase. There’s an example on the plugin’s homepage.

Further Reading

Traditionally, Maven plugins aren’t documented that well. But since hibernate3-maven-plugin is just a thin wrapper around Hibernate Tools, you can find documentation there.
There’s a lot more the plugin can do, especially if you’re not using JPA annotations, by the way.

Wednesday, October 16, 2013

Red Sector A

All that we can do is just survive
All that we can do to help ourselves
Is stay alive...


Sunday, October 13, 2013

Catcher In The Rye



When all is said and done
We're not the only ones
Who look at life this way
That's what the old folks say
But every time I see them
Makes me wish I had a gun
If I thought that I was crazy
Well I guess I'd have more fun
(Guess I'd have more fun)


Sunday, September 22, 2013

Thursday, September 19, 2013

Jethro Tull - Cross Eyed Mary

Déspotas

“Há três tipos de déspotas. Aquele que tiraniza o corpo, aquele que tiraniza a alma e o que tiraniza, ao mesmo tempo, o corpo e a alma. O primeiro é chamado de príncipe, o segundo de papa e o terceiro de povo”.

Oscar Wilde


Saturday, September 07, 2013

Awesome

7 Economic Attributes Compared

Think about economy. The main question is "mind set".

Market Economy (AS-IS) Earth Economy (TO-BE)
Consumption Preservation
Obsolescence Optimum Design
Property Access
Infinite Growth Steady State
Competition Collaboration
Labor for Income Mechanization
Scacity/Imbalance Abundance/Equality

Thursday, September 05, 2013

Best Best Practices Ever

  1. Write programs for people, not computers.
    1. a program should not require its readers to hold more than a handful of facts in memory at once
    2. names should be consistent, distinctive and meaningful
    3. code style and formatting should be consistent
    4. all aspects of software development should be broken down into tasks roughly an hour long
  2. Automate repetitive tasks.
    1. rely on the computer to repeat tasks
    2. save recent commands in a file for re-use
    3. use a build tool to automate scientific workflows
  3. Use the computer to record history.
    1. software tools should be  used to track computational work automatically
  4. Make incremental changes.
    1. work in small steps with frequent feedback and course correction
  5. Use version control.
    1. use a version control system
    2. everything that has been created manually should be put in version control
  6. Don’t repeat yourself (or others).
    1. every piece of data must have a single authoritative representation in the system
    2. code should be modularized rather than copied and pasted
    3. re-use code instead of rewriting it
  7. Plan for mistakes.
    1. add assertions to programs to check their operation
    2. use an off-the-shelf unit testing library
    3. use all available oracles when testing programs
    4. turn bugs into test cases
    5. use a symbolic debugger
  8. Optimize software only after it works correctly.
    1. use a profiler to identify bottlenecks
    2. write code in the highest-level language possible
  9. Document design and purpose, not mechanics.
    1. document interfaces and reasons, not implementations
    2. refactor code instead of explaining how it works
    3. embed the documentation for a piece of software in that software
  10. Collaborate.
    1. use pre-merge code reviews
    2. use pair programming when bringing someone new up to speed and when tackling particularly tricky problems
The only extra I would have included would be:
11. Maintain and update older code.

Sunday, September 01, 2013

Expressões Idiomáticas - Idioms

A Língua Inglesa possui algumas armadilhas para quem não a fala como língua materna, dentre elas estão as Expressões Idiomáticas (Idioms), que são figuras de linguagem onde um termo ou a frase assume um significado diferente do que as palavras teriam isoladamente. Assim, não basta saber o significado das palavras que formam a frase, é preciso olhar para todo o grupo de palavras que constitui a expressão para entender o seu significado. As Expressões Idiomáticas trazem conotações diferentes, que, na maioria das vezes, estão relacionadas às suas origens. É importante salientar que os idiomatismos não foram criados para serem armadilhas para os falantes estrangeiros, pelo contrário, elas tornam o Inglês Falado (Spoken English) mais natural. Relacionamos abaixo alguns exemplos de Expressões Idiomáticas mais usadas pelos falantes nativos da Língua Inglesa.

Act your age = Não seja infantil

All day long = O dia todo

Beyond a shadow of doubt = Sem sombra de dúvida

Blood is thicker than water = Os laços de família são mais fortes

Cross my heart = Juro por Deus

Everybody says so =Todos falam assim!

For goodness’ sake! = Pelo amor de Deus!

Good Lord! = Meu Deus!

Hand in Hand = De mãos dadas

I did quite well = Sai-me muito bem

Keep your eyes peeled = Fique atento
Leave it to me = Deixa comigo

Like hell! = Uma ova!

May I have the floor? = Posso falar?

Mum’s the word = Boca de siri
Never heard of = Nunca ouvi dizer

Never mind = Deixa prá lá / Não tem importância

Once and for all = De uma vez por todas

One never knows = Nunca se sabe

Pretty soon = Em breve

Quite a bit = muito, um montão, bastante, um bocado

Right over there = Logo ali

See you there = Até lá

Shoot the works = Manda brasa

Talk is cheap = Falar é fácil

Thank God = Graças a Deus

It is up to you = Você que sabe

You know best = Você é quem sabe

Take your time = Não se apresse

So far, so good? = Até aqui, tudo bem?

It is not your business = Não é da sua conta

To kick the bucket = Bater as botas / Morrer

How come? = Como é que pode?

How are you doing? = Como está?