Cross-Database Table Mapping
Suppose the connection uses one database, while the required table is appdb.sales.user_info. Set both the database and schema on the entity:
import net.hasor.dbvisitor.mapping.Table;
import net.hasor.dbvisitor.mapping.Column;
@Table(value = "user_info", catalog = "appdb", schema = "sales",
useDelimited = true)
public class UserInfo {
@Column(primary = true)
private Integer id;
private String name;
// Getters and setters omitted
}
UserInfo user = lambda.query(UserInfo.class)
.eq(UserInfo::getId, 1001)
.queryForObject();
The query accesses [appdb].[sales].[user_info].
Note
If you set catalog but omit schema, dbVisitor uses dbo. For the example above, omitting schema="sales" would access the wrong table. Keep the explicit schema.
For tables in the connected database, omit catalog and keep schema. See Object Mapping for common mapping options.