mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Fix Column handling
This commit is contained in:
parent
cfa11f5095
commit
e18a586065
@ -57,7 +57,11 @@ public final class NativeSQLSerializer extends SQLSerializer {
|
||||
if (path.getAnnotatedElement().isAnnotationPresent(Column.class)) {
|
||||
SQLTemplates templates = getTemplates();
|
||||
Column column = path.getAnnotatedElement().getAnnotation(Column.class);
|
||||
append(templates.quoteIdentifier(column.name(), precededByDot));
|
||||
if (!column.name().isEmpty()) {
|
||||
append(templates.quoteIdentifier(column.name(), precededByDot));
|
||||
} else {
|
||||
super.appendAsColumnName(path, precededByDot);
|
||||
}
|
||||
} else {
|
||||
super.appendAsColumnName(path, precededByDot);
|
||||
}
|
||||
|
||||
@ -15,10 +15,13 @@ package com.querydsl.jpa;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.persistence.Column;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.querydsl.core.DefaultQueryMetadata;
|
||||
import com.querydsl.core.JoinType;
|
||||
import com.querydsl.core.types.path.PathBuilder;
|
||||
import com.querydsl.jpa.domain.sql.SAnimal;
|
||||
import com.querydsl.sql.Configuration;
|
||||
import com.querydsl.sql.MySQLTemplates;
|
||||
@ -26,6 +29,14 @@ import com.querydsl.sql.MySQLTemplates;
|
||||
|
||||
public class NativeSQLSerializerTest {
|
||||
|
||||
public static class Entity {
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Column(name="first_name")
|
||||
private String firstName;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In() {
|
||||
Configuration conf = new Configuration(new MySQLTemplates());
|
||||
@ -41,4 +52,22 @@ public class NativeSQLSerializerTest {
|
||||
"where animal_.name in (?1, ?2)", serializer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Path_Column() {
|
||||
PathBuilder<Entity> entity = new PathBuilder<Entity>(Entity.class,"entity");
|
||||
Configuration conf = new Configuration(new MySQLTemplates());
|
||||
NativeSQLSerializer serializer = new NativeSQLSerializer(conf, true);
|
||||
serializer.handle(entity.get("name"));
|
||||
assertEquals("entity.name", serializer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Path_Column2() {
|
||||
PathBuilder<Entity> entity = new PathBuilder<Entity>(Entity.class,"entity");
|
||||
Configuration conf = new Configuration(new MySQLTemplates());
|
||||
NativeSQLSerializer serializer = new NativeSQLSerializer(conf, true);
|
||||
serializer.handle(entity.get("firstName"));
|
||||
assertEquals("entity.first_name", serializer.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user