Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring:类可以同时是@Document和@Table吗_Java_Spring_Mongodb_Spring Mvc_Cassandra - Fatal编程技术网

Java Spring:类可以同时是@Document和@Table吗

Java Spring:类可以同时是@Document和@Table吗,java,spring,mongodb,spring-mvc,cassandra,Java,Spring,Mongodb,Spring Mvc,Cassandra,我在MVC环境中使用spring。我与卡桑德拉和莫诺格达合作。对于这个项目,我必须使我的模型和dao类与这两个数据库兼容。是否可以将相同的模型类设置为@Document,也可以设置为@Table?spring能够在运行时进行区分吗 例如,对于mongo,我将 @Document public class Book{ @Id private String uniqueId; /*Other details*/ } @Table public class Book{

我在MVC环境中使用spring。我与卡桑德拉和莫诺格达合作。对于这个项目,我必须使我的模型和dao类与这两个数据库兼容。是否可以将相同的模型类设置为
@Document
,也可以设置为
@Table
?spring能够在运行时进行区分吗

例如,对于mongo,我将

@Document
public class Book{

    @Id
    private String uniqueId;

    /*Other details*/
}
@Table
public class Book{

    @PrimaryKeyColumn(name = "uniqueId", ordinal = 0, type = PrimaryKeyType.PARTITIONED, ordering = Ordering.ASCENDING)
    private String uniqueId;

    /*Other details*/
}
而对于卡桑德拉,我将

@Document
public class Book{

    @Id
    private String uniqueId;

    /*Other details*/
}
@Table
public class Book{

    @PrimaryKeyColumn(name = "uniqueId", ordinal = 0, type = PrimaryKeyType.PARTITIONED, ordering = Ordering.ASCENDING)
    private String uniqueId;

    /*Other details*/
}
能给我点类似的吗

@Table
@Document
public class Book{

    @PrimaryKeyColumn(name = "uniqueId", ordinal = 0, type = PrimaryKeyType.PARTITIONED, ordering = Ordering.ASCENDING)
    @Id
    private String uniqueId;

    /*Other details*/
}

是的,如果您有正确的存储库配置,这是可能的。有关具体详细信息,请参阅。

是的,如果您有正确的存储库配置,则可以使用。有关具体细节,请参见。

是的,这是非常可能的。一个典型的例子是,您希望在本地/测试和生产环境中拥有不同的数据源。您可以在测试环境中使用Mongo,在生产环境中使用MySql。因此,您可以同时使用
spring-data-mongo
javax.persistence
annotations

是的,这是非常可能的。一个典型的例子是,您希望在本地/测试和生产环境中拥有不同的数据源。您可以在测试环境中使用Mongo,在生产环境中使用MySql。因此,您可以同时使用
spring-data-mongo
javax.persistence
annotations

在询问之前,您应该先尝试一下。这个特定的用例应该是有效的。我要试一试!在询问之前,你应该先自己尝试一下。这个特定的用例应该是有效的。我要试一试!