ActiveJDBC – as ORM : ActiveJDBC logging & Primary Key
ActiveJDBC logging & Primary Key |
ActiveJDBC logging configuration
- ActiveJDBC uses SLF4J logging facade.
- ActiveJDBC uses a system property activejdbc.log for specifying logging. The value of this property can be:
- blank – in this case, ActiveJDBC will spit out all available information – every SQL statement, cache hits/misses, cache purge events, etc.
- regular expression – in this case, ActiveJDBC will only log statements that match a regular expression
Example
If you just want to see all messages from ActiveJDBC, start your program like this.
java -Dactivejdbc.log com.javaskool.YourProgram
-If you only want to see select messages, you can provide an expression
java -Dactivejdbc.log=select.* com.javaskool.YourProgram
Primary Key
- ActiveJDBC, like ActiveRecord relies on the surrogate primary keys. A surrogate key is not generated by ActiveJDBC. Unlike Hibernate, it does not (currently)
have any generators for the keys and relies fully on DBMS solution to do this. - By convention, the primary key name is id. If your table has a surrogate primary key column with a name id, you do not have to do anything.
Override primary key
- If your table cannot provide a primary key column named id (for instance due to corporate naming standards), you can override it with @IdName annotation.
- Example: let’s say you have a table Flight
CREATE TABLE Flight(
flight_id int(11) NOT NULL AUTO_INCREMENT,
Src VARCHAR(124),
Dest VARCHAR(124),
)
You will then put annotation on the model
@IdName("flight_id")
public class Flight extends Model{}
Composite Primary Keys
- Like ActiveRecord, ActiveJDBC does not support composite primary keys.
- However, this does not mean that you cannot use AJ on tables with declared composite PKs.
- All it means is that AJ does not provide any constraint checks, and relies on the DB for that.
Recent Comments