我有一个共享(与其他应用程序)Cassandra数据库,它集中在2个不同的节点 . 我正在使用Cassandra Database 2.1.2和Java Datastax驱动程序版本2.1.4 .

我创建了类似于此的Do:

package com.me.name.data.model.cassandra;

@Table(name = "name")
public final class NameDo
{
/*
 * the unique identifier
 */
@PartitionKey
private UUID            id;

/*
 * The package name
 */
@Column(name = "name")
private String          name;

/*
 * the version number
 */
@Column(name = "version")
private String          version;

/*
 * the trial period configured.
 */
@Column(name = "period")
private Integer         period;

/*
 * The last update date
 */
@Column(name = "status_last_update")
private Date            statusLastUpdate;

/*
 * The trial start date
 */
@Column(name = "trial_start_date")
private Date            trialStartDate;

/*
 * The description
 */
@Column(name = "description")
private String           description;

我正在使用这样的集群:

public final class ClusterManagerServiceImpl implements ClusterManagerService
{
private @Value("${cassandra.contactpoints}") String clusterHost;
private Cluster                                     cluster;
private static final Logger                         LOGGER = Logger.getLogger(ClusterManagerServiceImpl.class);

@Autowired
private AuthProviderImpl authProvider;

public String getClusterHost()
{
    return clusterHost;
}

public void setClusterHost(String clusterHost)
{
    this.clusterHost = clusterHost;
}

public Cluster getCluster()
{
    if (cluster == null)
    {
        try
        {
            this.createCluster();
        }
        catch (UnknownHostException e)
        {
            LOGGER.error(e);
        }
    }
    return cluster;
}

public void setCluster(Cluster cluster)
{
    this.cluster = cluster;
}

public void createCluster() throws UnknownHostException
{
    try
    {
        if (cluster == null)
        {
            LOGGER.debug("opening new Cluster");
            setCluster(Cluster.builder().withAuthProvider(authProvider).addContactPoints(InetAddress.getByName(getClusterHost())).build());
        }
    }
    catch (UnknownHostException e)
    {
        LOGGER.error(e);
    }
}

所以每次我想做更新或插入时我都这样做:

protected Session createSessionOnCluster(Session session) {
    LOGGER.debug("opening new session");
    session = clusterManagerServiceImpl.getCluster().connect(KEYSPACE_NAME);

    return (session);
}

private Mapper<NameDo> createPackageMapper(Session session) {
    MappingManager manager = new MappingManager(session);
    Mapper<NameDo> mapper = manager.mapper(NameDo.class);
    return mapper;
}

public NameDo updateName(NameDo nameDo)
        {
    Session session = null;

    nameDo.setStatusLastUpdate(new Date());
    session = createSessionOnCluster(session);

    Mapper<NameDo> mapper = createPackageMapper(session);
    mapper.save(nameDo);

    return nameDo;
}

所以...毕竟这......我正在进行更新,它根本不会抛出任何错误,但在我检查数据库之后,我的名表没有更新...

  • 有谁知道是什么原因引起的?

  • 是 Cassandra 吗?

  • 是DataStax驱动程序吗?

  • 有解决方法吗?