Java EE

XML should be readable for humans. Therefore you will have to print XML output with correct indentation and line breaks.

JAXB is not doing so by default, also not using Spring.

In order to enable so called pretty printing for XML files generated using JAXB, you will have to modify the context.xml in your Java Spring project.

XML

In case you are dealing with large amounts of data, processed into a schema generated using Hibernate you might want to create some indexes to speed up selects.

This can be easily achieved using the @Index annotation.

Here is a short example creating an index based on only one column called system. Indexes can be created independently from primary keys, indicated by @Id.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
@Entity
@Table(name = "A_Table_Name", indexes = { @Index(columnList = "system", name = "inx_system") })
public class ATableName implements Serializable {
    private static final long serialVersionUID = 7175559932832558291L;
	@Column
	private String environment;
	@Column
	@Id
	private String system;
	@Column
	@Id
	private String id;
...

 If you want to create an index consisting of more than one column, you simply provide all needed columns in the columnList like shown in below example. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
@Entity
@Table(name = "A_Table_Name", indexes = { @Index(columnList = "system,id,environment", name = "inx_system_id_env") })
public class ATableName implements Serializable {
    private static final long serialVersionUID = 7175559932832558291L;
	@Column
	private String environment;
	@Column
	@Id
	private String system;
	@Column
	@Id
	private String id;
...

Enjoy.

If you want to create a table with an auto increment id column in JavaDB (Derby), the following SQL will do the trick for you applying some rules.

Source Code

The bold part is defining the column called 'ID' to be automatically generated and incremented by 1 every time a new record is written to the table.

1
2
3
4
5
6
CREATE TABLE "aTable"(
   "ID" INT not null primary key
        GENERATED ALWAYS AS IDENTITY
        (START WITH 1, INCREMENT BY 1),
   "Column_Name" VARCHAR(50)
);

Subcategories

A category to group articles related to Spring and Hibernate.