Can Java Persistence detect the database (Postgres,MySQL,etc.) dynamically?
843830Apr 21 2009 — edited Apr 23 2009I need to develop a generic application which could be used for different databases, such as PostgreSQL, MySQL, Oracle, Sybase, etc. Each database has different requirements and data types which I need to map to the correct ones using @Column(columnDefinition="XXX", length=xxx) annotations.
Is there anyway to DYNAMICALLY DETECT the underlying database when the application is run? I would like my application to "know" what the database it is connecting to to generate the tables using the approprate annotations.
Also, is it possible to write conditional annotations, such as "if the database is PostgreSQL, then use these annotations... if the database is MySQL, then map this data type to XXX... etc." (This seems more like a Java 5 programming language topic, tough.) Any resources or documentation on how to do this?